user1612986
user1612986

Reputation: 1415

including library and dll into c++ project

I have a third party library (say, tp.lib) and the third party dll (say, tp.dll) which I need to use in my C++ project (my project makes a dll, lets call it my.dll).

I have included the library with the #pragma comment(lib, "libraryname") in the header file and also included the path of the library file in the configurationproperties->linker->additional library directories in my C++ Visual Studio project.

The code compiles and links okay. but fails to execute. When I used depends to check if i am missing something, I observed that the tp.dll is not found. The tp.dll resides in the same library folder where the tp.lib resides.

What should I do so that tp.dll gets included to my.dll?

Upvotes: 0

Views: 1446

Answers (3)

rerun
rerun

Reputation: 25505

The search path at runtime does not include the folder where you put the lib library, so putting the DLL with the lib is not enabling the OS to find it at runtime. You can add that to the path, or move the DLL. The list of search precedence is on MSDN.

Upvotes: 0

Mark Tolonen
Mark Tolonen

Reputation: 178369

DLLs have a different search path. Quote below from docs:

With both implicit and explicit linking, Windows first searches for "known DLLs", such as Kernel32.dll and User32.dll. Windows then searches for the DLLs in the following sequence:

  1. The directory where the executable module for the current process is located.

  2. The current directory.

  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

  5. The directories listed in the PATH environment variable.

Note The LIBPATH environment variable is not used.

Upvotes: 1

Zdeslav Vojkovic
Zdeslav Vojkovic

Reputation: 14591

You can't "include the dll into another dll". You need to either deploy them together, or put the dependency dll in a place where Windows will find it.

Upvotes: 0

Related Questions