Shared Library __declspec(dllexport) __declspec(dllimport) question
-
Hi,
im working on restructuring my application to go from statically linked to dynamically.
Right now I have a Core library which is statically linked into Project library which is statically linked into my Client.exe.
What I did to make my desired change happen:
Create core_global.h in the root directory of my Core library, add following code#include <QtCompilerDetection> #if defined(CORELIB) #define CORE_EXPORT Q_DECL_EXPORT #else #define CORE_EXPORT Q_DECL_IMPORT #endif
and use that macro for class/function export.
Now, when consuming the Core library in my Project library I had some strange behaviour:
The compiler complained that it can not find core_global.h.
This makes sense since this file is only present in the Core library.Now, how do I go about solving this problem?
I imagine I have to install the core_global.h in my
CMAKE_RUNTIME_OUTPUT_DIRECTORY
? But wouldnt this mean that (theoretically) I would have N x_global.h in that folder (assuming I have N shared libraries). And wouldnt that be a problem if a user decides to open that file and change the content?Im kinda lost here.
Thanks :)
-
When you want to include some headers of a library you also must pass the include path to the compiler.
If you use cmake, use target_include_directories() and add the desired include paths there. Later when you use this library (aka you link them with target_link_libraries()), cmake will automatically add the paths specified. -