`bash: ./a.out: No such file or directory` on running executable produced by `ld`

ld -lc a.o There are several things wrong with this command line: In general, user-level code should never use ld directly, and always use appropriate compiler front end (gcc here) to perform the link. As you have discovered, the link command line that gcc constructs is quite complicated, and the command line that you’ve accepted … Read more

Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what’s the dynamic library search algorithm with it?

As you’ve noted, DYLD_LIBRARY_PATH behaves like LD_LIBRARY_PATH on other *nix. However, there is another environment variable you should look at called DYLD_FALLBACK_LIBRARY_PATH. In general, these are (both on osx and linux) suggested only for development use as they can cause symbol lookup errors when you override with a library that does not have the same … Read more

What do linkers do?

To understand linkers, it helps to first understand what happens “under the hood” when you convert a source file (such as a C or C++ file) into an executable file (an executable file is a file that can be executed on your machine or someone else’s machine running the same machine architecture). Under the hood, … Read more