1

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 ?

Jörg Haubrichs
  • 2,215
  • 3
  • 24
  • 26

3 Answers3

6

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.

1

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.

ssube
  • 47,010
  • 7
  • 103
  • 140
  • 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 – Jörg Haubrichs Jul 29 '10 at 19:46
1

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
  • 223,662
  • 58
  • 417
  • 506