/* * This prints the location of the current binary as * reported by the dynamic linker. * It does not work on all UNIX-like platforms. * For instance, it doesn't on Linux. * * Link with: cc -o relocatability-test relocatability-test.c -ldl */ #define _GNU_SOURCE #include #include int main(int argc, char **argv) { Dl_info info; printf("argv[0] = %s\n", argv[0]); if (!dladdr(main, &info)) { fprintf(stderr, "Cannot query executable's path: %s\n", dlerror()); return 1; } printf("dli_fname = %s\n", info.dli_fname); return 0; }