views:

68

answers:

3

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 ?

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 ?

+1  A: 

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.

peachykeen
The pragma thing sounds interesting, my target is Linux/gcc though - seemingly there is no similar solution:http://stackoverflow.com/questions/1685206/pragma-commentlib-xxx-lib-equivalent-under-linux
Homer J. Simpson
+5  A: 

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.

anon
Ok, thank you - that's a result too.
Homer J. Simpson
+1  A: 

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.

nos