Let's say I know that some of my C/CPP files include certain headers - is there any reliable information aga开发者_运维百科inst which libraries I will have to link, other than guessing ?
For example, if I have something like
#include "foo.h"
and want to find
libfoo_abcdef_123.so
Is there any 'best practice' how to do that, any place where to look at ?
Despite what the other answers here say - no, there isn't. Libraries can (and sometimes do) redefine the same function and the only thing that can attempt to resolve such clashes is the linker, which knows zip about header files.
This doesn't work for everything, but if you're using your own headers (in a modular program, for example), you can include the library name in the header.
That's especially convenient in Visual Studio, where you can #pragma comment(lib, "thismodule.lib")
in the library header and the code including the library never has to worry. On other platforms/compilers, you may find similar commands.
Any good 3rd party library should have instructions on what to include, though.
Let's say I know that some of my C/CPP files include certain headers - is there any reliable information against which libraries I will have to link, other than guessing ?
Not really, but you'll usually find such information in the documentation for the functions/classes you're using.
精彩评论