Questions on creating a DLL

Started by
9 comments, last by Cluq 16 years, 1 month ago
Hello enlightened programmers! I have a couple of questions on which files to include in a release when building a DLL. 1) When creating a DLL and exporting methods from that DLL, Visual Studio creates a Project.dll, Project.lib and Project.exp (and some other files not important to this subject). - What is the .exp file used for? - Do I need to include that in my release for other people to link against my dll? I was of the belief that only the .dll, .lib and header files are needed? - If it is not needed, can I then somehow tell VS to output the .exp file to a different folder than the .lib file? (I would like for VS to output only the .dll and the .lib in one folder - the rest in some intermediate folder) 2) I am creating an .exe file that use the .dll. But when building the .exe file, VS also outputs a .lib and .exp file. Why on earth does it that for? - and can you tell it not to :) I hope that some of you brilliant guys will take the time to enlighten me a bit here. It will be much appreciated!
Advertisement
Quote:Original post by Cluq


2) I am creating an .exe file that use the .dll. But when building the .exe file, VS also outputs a .lib and .exp file. Why on earth does it that for? - and can you tell it not to :)

I hope that some of you brilliant guys will take the time to enlighten me a bit here. It will be much appreciated!


No, thats not normal, it should not output a .lib file when compiling an exe.
1. No idea. I presume it's just another intermediate file that lists the function exports. You can ignore it completely.

2. VC will generate a .lib file if you export symbols from your DLL or EXE. If you're getting a .lib generated for the EXE, that means the EXE is exporting symbols (Check with Depends.exe from the platform SDK). That's probably caused by using __declspec(dllexport) on functions that you're using in the DLL, without using the proper macros to select dllexport or dllimport depending on if you're building the DLL.

The usual method is to do something like:
#ifdef BUILDING_DLL#   define DLL_EXPORT __declspec(dllexport)#else#   define DLL_EXPORT __declspec(dllimport)#endifextern "C"{   DLL_EXPORT void SomeFunction();};

And then to defien BUILDING_DLL when building the DLL project.
You dont need to link the export file (.exp) because it is only needed for the linker to build the DLL. Probably you can specify the path somewhere in the projects properties ;)
Quote:Original post by GamerSg
No, thats not normal, it should not output a .lib file when compiling an exe.


In some cases, you want to export some .exe functions for your dll ( and not the other way ).
In this case, you declare those functions as dll_export, and VC generated a .lib (still for the exe).
Then you can link the dll with the exe's lib in order to use these functions.


For the rest Evil Steve had said it all.

Hope it helps,


Emmanuel


Ahh..yes - thank you Mr Evil :)

I have had my troubles with the dllimport/dllexport issue for a while now, and I finally got it working now - and you were exactly right! The .exe no longer outputs a .lib or a .exp file ;)

If anyone else can explain the .exp file and my questions in 1), it would be highly appreciated!

But many thanks so far!
First hit on Google: .exp Files as Linker Input
mmkay.. so the .exp file has to do with the fact that the .dll both exports and imports stuff..

I am not yet entirely sure that I understand why it is needed, but it seems that in my case I actually don't need it :)

Many thanks for the google link though - one might argue that I could have found that myself, but let us not get into that :D
Quote:Original post by rvdwerf
You dont need to link the export file (.exp) because it is only needed for the linker to build the DLL. Probably you can specify the path somewhere in the projects properties ;)


Yeah, that was what I was looking for too, but I haven't been able to find it anywhere!

Edit: I can specify the folder (and name) of the .lib file, but the .exp file just gets thrown along.
You can also write a post-build script to copy the files you want to another directory. It's pretty easy to do.

This topic is closed to new replies.

Advertisement