2

I have 3rd party library in my program.

For example :

#INCLUDE <3rdPartyHeaderA.h>
#INCLUDE <3rdPartyHeaderB.h>

int main(int argc, char** argv)
{
  // some stuff
}

How do i know 3rdPartyHeaderA.h is using which particular .lib or .dll. I looked over 3rdPartyHeaderA.h but there is no information.

I'm asking this question because i need to determine which .lib or .dll should I add into project environment since I don't wan to add all of them.

This might be a stupid question . if that so, feel free to vote down. Thanks.

EDIT : Thanks Wyzard for clarifying my question.

It's asking how to determine whether the functions declared in 3rdPartyHeaderA.h are defined in Foo.lib or Bar.lib (or Foo.dll or Bar.dll, or whatever). – Wyzard

LOK CARD
  • 293
  • 2
  • 16
  • possible duplicate of [When to use dynamic vs. static libraries](http://stackoverflow.com/questions/140061/when-to-use-dynamic-vs-static-libraries) – Tomas Kubes May 22 '15 at 03:55
  • @qub1n Definitely not. No mention of static vs. dynamic whatsoever. Read the question. – user207421 May 22 '15 at 04:34
  • It should be noted that there is also something which is called "Import Library" check http://stackoverflow.com/questions/3573475/how-does-the-import-library-work-details – Wakan Tanka Sep 08 '16 at 22:48

2 Answers2

1

You will almost certainly have to add them all, unless you know about their interdependencies. I don't know what the objection to that could possibly be.

user207421
  • 305,947
  • 44
  • 307
  • 483
1

There's no automatic way to "look up" which lib goes with a given header. When you compile, the linker simply takes all the function calls on one side and all the libs on the other side and starts matching.

Here are the standard solutions, in order from best to worst:

  1. Read the documentation that came with your library. Add the lib it tells you to. Usually there is some kind of comment or instruction telling you which libs export which header functions.

  2. Add every lib you can find. Obviously start with the ones that came with 3rdPartyHeader, then move on to the standard library. Keep adding until it compiles. Don't worry too much at this point about adding too many; it is usually safe to include libs that you don't use, as the linker simply won't bring in that code in your executable.

Once you get your program to compile with a long list of libs, you can start removing them one by one and trying to build again. If you take out xyz.lib and it still builds, then you didn't need that one.

  1. Finally, you can look inside the lib files to see which functions they export, and compare that to the list of functions in your header. See How to See the Contents of library for details. In most cases this is unnecessary. If you have the right libs, the linker will find your functions.
Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54