Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/CLI Managed DLL compiled against .lib fails to load, has .dll dependency. (VS2010)

In Visual Studio 2010, I've written a C++/CLI managed class wrapper for an external library provided as a .lib file, lets call it ExternalLibrary.lib. The .lib is included as a dependency of the project, and no warnings or errors are issued on compilation.

When I attempt to use this wrapper project by including it as a dependency of a C# project, I get the following error when I run in debug mode (project silently fails to run without debugging):

FileNotFoundException was unhandled
Could not load file or assembly 'WrapperProject.dll' or one of its dependencies.
The specified module could not be found

I verified that WrapperProject.dll is in the debug folder of the C# project, so I decided to check its dependencies using Dependency Walker (http://dependencywalker.com/) The first dependency on the list was "ExternalLibrary.dll". I think this is the problem, because "ExternalLibrary.dll" never existed, only "ExternalLibrary.lib." How do I tell Visual Studio to not require the non-existent DLL, and instead incorporate the .lib file?

It already throws an error if I remove the .lib from the linker path, so it's looking for and finding the file; I'm not sure why at the end it would add a dependenency on a non-existent .dll.

Thanks

like image 814
Corey Staten Avatar asked Dec 06 '25 08:12

Corey Staten


1 Answers

You can't - the DLL will always be required. The .LIB file is the import library for that DLL.

Linking against the .lib file just tells the compiler how to load the proper information from the corresponding .DLL (ExternalLibrary.dll) at runtime. The .DLL is still required, and will need to be deployed along with your application.

like image 82
Reed Copsey Avatar answered Dec 08 '25 00:12

Reed Copsey