471,071 Members | 962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

DLLs and static libraries

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

#include "staticlib.h"

class dllinterface
virtual funct1()=0;
virtual funct2()=0;

class mydll:public dllinterface


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.

Sep 22 '06 #1
3 6669
9,065 Expert Mod 8TB
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
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
Sep 23 '06 #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.

Similar topics

4 posts views Thread by John Hunter | last post: by
1 post views Thread by Leslaw Bieniasz | last post: by
7 posts views Thread by richard pickworth | last post: by
5 posts views Thread by Rich | last post: by
6 posts views Thread by Brian Bischof | last post: by
2 posts views Thread by ClydeL | last post: by
7 posts views Thread by Jeff Lynn | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.