What happens if I at compile time specify开发者_如何学C library that is actually not used? Does my program still depends on it?
I know that the question might be stupid (why someone would link library if he not use it?), but here is the case:
I am building QT from source and I want to include MySQL driver. But since there is some changes since last version, the usually documented way is not usable. The only way that I can specify libraries is to use configure.exe for whole QT. This means that other libraries like QtCore or QtNetwork will be compiled like g++ ...... -lmysql, although they don't use any function from this library. The question is, does these libraries now actually depend on mysql or not? Will I be able to run program if I don't use mysql driver and there is no mysql library present?
EDIT: I am using MinGW on Windows 7.
Usually, yes, the executable depends on the libraries it's linked against.
If you're using gcc, you can use the linker flag --as-needed
, this will make the linker omit references to libraries whose symbols are not used.
Note that it can make a difference, because merely loading libraries can have perceivable effects (their init sections may run, etc.)
This depends fully on the linker, i.e. the compiler involved. Since dpkg-shlibs is able to determine when executables are uselessly linked against shared libraries, I think that for the gcc's ld the answer is "yes, they will actually depend on the linked library".
精彩评论