tags:

views:

169

answers:

2

I have a dll and an exe, both of which I have the sources to.

For the DLL I have compiled completely statically and therefore, I would assume that the the .lib is also static. However, when I include that lib in my C++ VC++ 2008 project under Linker > Input > Additional Dependencies . I set the compile mode to /MT (multi-threaded) for the exe.

Everything compiles, but when I try to run the exe, it asks for the dll! To the best of my (limited) understanding, that shouldn't be happening.

Why should I do?

+6  A: 

The 'compile mode' setting that you are referring to is the setting for the runtime library that gets linked with whatever library or executable you produce.

If your project is set up to produce a DLL (check the main project page), then it'll still produce a DLL no matter what you're putting into the runtime library setting. What I think you want to do is change the setting on the DLL's main project page from DLL to Static Library instead of changing the runtime library setting.

Once you've done this, make sure that both the executable and library projects have the same runtime library setting (the /MT switch you refer to), otherwise you'll get tons of strange error messages if the linker is trying to match up two different runtime libraries in the same executable.

Timo Geusch
hmmm... That seems to make sense... I am trying that now.
Ramblingwood
I am having trouble changing my makefile from a DLL to a static library.
Ramblingwood
I have a static library now. I put it as an additional dependency and still it asks for the DLL when I start it.
Ramblingwood
Clear out all your old compilation results and check that you haven't got a copy of the old DLL around that you're inadvertently linking against.
Timo Geusch
I just tested it with two other simple projects I had laying around and it worked great. I think there is just something too complex in my current project (it is rather hacked together), so I will take the time this weekend to fix it all up.
Ramblingwood
+3  A: 

The .lib file that is created with a "static" DLL is just an import library that handles automatic dynamic linking to all the symbols in the library. The DLL itself (that is, the .dll file) still contains all the code/symbols/etc. that you expect.

Statically linking to the .lib file just saves you from manually calling LoadLibrary()/GetProcAddress(), etc. to resolve symbols within the DLL.

You'll still need the DLL itself unless you build a true static library (that is, with all the symbols & code, rather than just the imports).

Drew Hall
ah. thanks for the explanation. now i just have to reconfigure my project to be a static lib instead of a dll.
Ramblingwood
I put the static library as an dependency and it still asks for the DLL.
Ramblingwood
@Ramblingwood: Sounds like you're still building a DLL + static import lib, rather than a static code library. Until you do that, you won't be able to get rid of the DLL.
Drew Hall
I'm not, only a .lib is outputed and that lib is referenced in the project. As I said above: I just tested it with two other simple projects I had laying around and it worked great. I think there is just something too complex in my current project (it is rather hacked together), so I will take the time this weekend to fix it all up.
Ramblingwood
@Ramblingwood: Good luck!
Drew Hall