Jörg Haubrichs
Jörg Haubrichs

Reputation: 2243

Is there any way to deduce link flags from headers?

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 ?

Upvotes: 1

Views: 168

Answers (3)

nos
nos

Reputation: 229098

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.

Upvotes: 1

anon
anon

Reputation:

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.

Upvotes: 6

ssube
ssube

Reputation: 48267

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.

Upvotes: 1

Related Questions