dynamic-linking
MySQL Improperly Configured Reason: unsafe use of relative path
In OS X El Capitan (10.11), Apple added System Integrity Protection. This prevents programs in protected locations like /usr from calling a shared library that uses a relative reference to another shared library. In the case of _mysql.so, it contains a relative reference to the shared library libmysqlclient.18.dylib. In the future, the shared library _mysql.so … Read more
Linking GLEW with CMake
Typical CMake scripts like FindGLEW will define variables that specify the paths and files that your project needs. If the script can’t automatically identify the correct paths (usually because of nonstandard install location, which is fine), then it leaves these variables up to you to fill in. With command line CMake, you use the -D … Read more
`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
dlopen from memory?
I needed a solution to this because I have a scriptable system that has no filesystem (using blobs from a database) and needs to load binary plugins to support some scripts. This is the solution I came up with which works on FreeBSD but may not be portable. void *dlblob(const void *blob, size_t len) { … Read more
Force GCC to notify about undefined references in shared libraries
-Wl,–no-undefined linker option can be used when building shared library, undefined symbols will be shown as linker errors. g++ -shared -Wl,-soname,libmylib.so.5 -Wl,–no-undefined \ -o libmylib.so.1.1 mylib.o -lthirdpartylib
Linking two shared libraries with some of the same symbols
There are several ways to solve this: Pass -Bsymbolic or -Bsymbolic-functions to the linker. This has a global effect: every reference to a global symbol (of function type for -Bsymbolic-functions) that can be resolved to a symbol in the library is resolved to that symbol. With this you lose the ability to interpose internal library … Read more