By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

DLLs and static libraries

P: 3
I'm trying to create a dll that reads from a static library that I also wrote.So I have my dll and works fine but when the static library comes in it has problems. first if I add the header for the static library works fine but when I call any function for it it tells me that there is a link error "error LNK2019: unresolved external symbol "

The dll does not include the header of the static library directly, it is included in the interface of the dll, if I add it to the header of the dll I get the same results.

All classes in my static library have a __declspec (dllexport)

So its like this

//dllInterface.h
#include "staticlib.h"

class dllinterface
{
virtual funct1()=0;
virtual funct2()=0;
....
}

//mydll.h
class mydll:public dllinterface
{
funct1();
funct2();
...
}

//mydll.cpp
funct1()
{
callsomefunctionfromStaticLibrary();
}
funct2()
{
.....
}

Basically if I did not have the callsomefunctionfromStaticLibrary() call everything will compile with no errors, when I use anything from the library the compiler(msvs 2005) give me error LNK2019 for every function called from the static library.
Well its my first time making dlls so I'm pretty lost, I can tell you that if I include "staticlib.cpp" in my "mydll.cpp" everything compiles with no problems and the dll runs but I think something bad will happend later using this solution because I dont think that its correct to add a .cpp file into another cpp to fix the problem.
Thanks for your time.

Lars
Sep 22 '06 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
A dll is an executable and all symbol (function and variable) references must be defined for it to link successfully.

What you have probably done is left the staticlib.lib file out of the link of the dll.

You build process should be something like

1. Compile static library source files into object files
2. Link static library object files into .lib file
3. Compile dynamic library source files into object files
4. Link dynamic library object files and static library .lib file into a .dll and a .lib
Sep 22 '06 #2

P: 3
You are right !!.. I was able to link the lib to my dll and works fine thanks a lot.
But now I have another problem , all the global variables and functions in the library are showing as errors error LNK2005: already defined in the dll.obj, when I remove them and just use the classes in the library it works fine.. it there a way around this problems without getting rid of the global variables and functions?.. y tried #ifndef #define #endif and using #pragma once in the library but they dont take care of the global variables and functions....

Thanks for the time
Lars
Sep 23 '06 #3

P: 3
ok never mind I created a class with static variables and functions and everything compiles smooth, thanks
Sep 23 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.