Im trying to get the path of text file , when i use the method "realpath" & #include<stdlib.h> ,the compiler gives me an error message :"undefined reference to realpath"
Some programmer dude
411k36 gold badges421 silver badges655 bronze badges
1 Answer 1
realpath doesn't exist on Windows, which isn't fully POSIX compliant.
On Windows you can try to define it this:
#include <stdlib.h>
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
I know this works with MinGW-w64, but it should work with MSVC too.
If you're writing portable code you can just put this somewhere at the top to keep your code working for multiple platforms:
#ifdef _WIN32
#include <stdlib.h>
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#endif
answered Jan 3, 2023 at 19:03
Brecht Sanders
7,4111 gold badge24 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-c
realpathis a POSIX function. That means it's standard in Linux and macOS, but doesn't exist for Windows. So what operating system are you working on?PathCanonicalize?