Mauro Ganswer
Mauro Ganswer

Reputation: 1419

How to integrate third-party libraries in my dll?

I've a MSVS solution with two C++ projects. Project A is a DLL linked to third-party libraries (tp1.lib and tp2.lib) and it is referenced by project B, the exe. Everything compiles properly, but when I run B.exe I get the error for tp1.dll missing, while I would expect that the relevant portion of the code inside the third-party libraries should have been pulled into my A.dll.

Is this my assumption wrong? If not, I would need for you to know which settings can cause this behaviour. Among other settings, these are those for Project A under Properties>ConfigurationProperties that I guess are relevant:

Then, in A.h I have:

#include "tp1.h"
#include "tp2.h"

and in A.cpp

#include "stdafx.h"
#include "A.h"

Upvotes: 0

Views: 1421

Answers (1)

stgatilov
stgatilov

Reputation: 5533

It seems that tp1.lib and tp2.lib are import libraries for tp1.dll and tp2.dll. They do not contain any real code, only some helpers to redirect all the calls you make to those libraries to the proper addresses in the DLL.

When you link against an import library of a DLL, the DLL is not included into resulting binary. That's why the resulting binary needs the DLL file at the moment it is launched: it searches for it at startup, and crashes if it is not found.

If you want to add all the code from libraries tp1 and tp2 into your binary, you have to rebuild them as a static libraries (without any DLLs). Then linking against tp1.lib and tp2.lib would work as you expect.

Upvotes: 3

Related Questions