Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLL Project doesn't generate .exp and .lib file

So, I have a c++ solution which contains 3 project ( 2 DLL, and 1 .exe).

here's the basic dependencies representation:

Application --> DLL2

Application --> DLL1

DLL2 --> DLL1

The problem I have is that DLL2 (when building it) does generate the .dll but doesn't generate the .lib and .exp I need to reference properly DLL2 in the Application project. However, DLL1 does generate these files and I've compared DLL1's settings to DLL2's, and I can't find what the difference could be.

like image 671
TurnsCoffeeIntoScripts Avatar asked Nov 01 '12 13:11

TurnsCoffeeIntoScripts


People also ask

How do I create a .LIB file in Visual Studio?

To create a static library project in Visual StudioOn the menu bar, choose File > New > Project to open the Create a New Project dialog. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.

Can a exe link to DLL and static library at the same time?

Yes, the Core and Utils code will be duplicated. Instead of building them as static libs you can build them as dlls and use anywhere. Save this answer.


3 Answers

The simple explanation for that is that you just forgot to export anything. The linker won't create a .lib/.exp file if there are no exports. You can verify this by running dumpbin.exe /exports on the DLL. With the expectation that you see nothing.

Use __declspec(dllexport) to export symbols from the DLL. Or a .def file.

like image 169
Hans Passant Avatar answered Oct 29 '22 17:10

Hans Passant


The problem was that DLL2 had only .h files and no content in any of the associated .cpp files. So the IDE didn't see the neccesity of creating the .lib file.

like image 30
TurnsCoffeeIntoScripts Avatar answered Oct 29 '22 15:10

TurnsCoffeeIntoScripts


I just discovered another way to cause the same thing to happen. I moved some routines that I developed and tested as service routines in another DLL into a DLL of their own. Since this move was planned before I wrote the first line of code, they weren't marked for export, and were, hence, using that project's default calling convention, __cdecl. When I built the library, the build environment didn't create a .LIB file. After some investigation, and inspired by the mention of __declspec(dllimport) in this topic, I realized that, although I moved the declarations into the template header file generated by the New Project Wizard, I forgot to insert the name of the generated calling convention macro into the prototypes.

With the calling convention specified, both in the header and the CPP files that hold the implementations, I got the expected .LIB file.

like image 20
David A. Gray Avatar answered Oct 29 '22 16:10

David A. Gray