dll inside lib

Hey,

I've created a lib project which uses functionality of an external .dll file. If I use the resulting .lib in another project, I always get "unresolved external symbol" errors for the functions of the .dll which are called inside the lib. Is it even possible to use a .dll inside a lib project or do I have to link the .dll statically instead? Are the function calls to the .dll replaced by the code or does the dependency to the dll remain? I mean, I think I understand the concept of dynamic and static linking and how they behave (dlls are linked, lib code is copied into), but how does this apply when building a library and not using them?
Also, what would happen if I use an external dll inside a dll project? Can I somehow "merge" them, so that the created dll contains the external one?

Greetings
Is it even possible to use a .dll inside a lib project
Yes.

do I have to link the .dll statically instead?
That's not possible.

I mean, I think I understand the concept of dynamic and static linking and how they behave (dlls are linked, lib code is copied into)
All code needs to be linked before being executed, and linking involves, among other things, copying code to a common region.
The difference between DLLs and static libraries is when and potentially how, not whether, the linking occurs.

Also, what would happen if I use an external dll inside a dll project? Can I somehow "merge" them, so that the created dll contains the external one?
The short answer is no. The long answer is yes, by including the DLL file as an array in your program, then at run time copying it to disk, loading it, and getting pointers to its functions. It's very cumbersome and generally not worth it.

I've created a lib project which uses functionality of an external .dll file. If I use the resulting .lib in another project, I always get "unresolved external symbol" errors for the functions of the .dll which are called inside the lib
There's two kinds of DLLs: export-based DLLs are designed to be explicitly loaded by the programmer at run time. LIB-based DLLs provide a LIB which you link to at link time that does for you the work of loading the DLL and initializing pointers to its exports.
Which kind do you have?
Sorry for my late answer, I was busy in the last days..

I'm using GLEW, where i have to include a .lib, so I think its a lib based dll? Whats the difference between lib based and export based dlls then? How do i get the dll to copy its code into my code directly after compiling my .lib and not when using it?
Last edited on
Whats the difference between lib based and export based dlls then?
With an export DLL, you typically do this in your own code:
1
2
3
4
//int (*function_pointer)(int);
mod = LoadLibrary("foo.dll");
function_pointer = GetProcAddress(mod, "SomeFunctionDefinedInTheDll");
function_pointer(42);
This is inconvenient because you have to define a typedef and call GetProcAddress() for each function you want to use. LIBs do this for you.

How do i get the dll to copy its code into my code directly after compiling my .lib and not when using it?
As I said above, that's not possible.
Thank you very much!

I'm using libs instead of dll now and it's working as intended.
Topic archived. No new replies allowed.