I have a dll with a class that define some methods and variables inside it. I marked it as
__declspec(dllexport)
and i imported the .h header inside a win32 application project in the same solution. I can use the functions but when I try to compile the project I have a lot of errors about external symbols not resolved. Why?
Please read about the standard way of using macros for this very common task here: http://wiki.tcl.tk/8721
The basic idea is that you define a macro, say
MY_API
like so:When you declare a function or a class in the header file you do this:
When you build your own dll which declares the body of the function, you add the definition of
BUILD_MYAPI
to the build. This makes all declerations to bedllexport
when you include the header from some other dll you don't add
BUILD_MYAPI
so the decelerations aredllimport
When compiling with visual studio, you can add a macro definition to the compilation without changing the source from project properties -> C/C++ -> Preprocesson -> Preprocessor definitions