Hi!
I have a project, and I want that the source code of this project can be compiled as .lib file or .dll file. How do I do this?
I think that I should use # ifdef and stuff like that, but I don't know how to declare that.
Printable View
Hi!
I have a project, and I want that the source code of this project can be compiled as .lib file or .dll file. How do I do this?
I think that I should use # ifdef and stuff like that, but I don't know how to declare that.
Well you create a lib project and a dll project
You add all your source files to both of them
You tweak the code so that the lib project builds correctly
You then try and tweak the code so that the dll project builds correctly, but any changes you make are put inside conditional compilation
Say, for the sake of argument, that something should be static in a lib, but extern in a dll, then you would do this
Then you edit the dll project, and in the 'additional pre-processor switches', you add BUILDING_DLLCode:#if BUILDING_DLL
/* stuff you want for dll builds */
extern int var;
#else
/* stuff you want for lib builds */
static int var;
#endif
/* stuff common to both */
void foo ( void ) {
var = 1;
}