At the moment I have an application and a (static) library, both written in Qt. As build system I use cmake. I link the library with target_link_libraries
to the executable and everything works fine (and I have one file/executable).
But now I want to use a shared library. Creating a shared library with add_library
and the keyword SHARED
works, but I am a bit confused about the way, how to load a shared library. I saw two "ways":
- Write a library and use
Q_DECL_EXPORT
/ Q_DECL_IMPORT
. They load the library with QLibrary
and use a typecast to resolve all (C) functions
- Write a library and include the header file in the application. The shared library is "passed" to the executable with the cmake command
target_link_libraries
. They don't use QLibrary to load the library.
Now I have a few questions:
- What is the common ("normal") way to load a shared library ? Export all C++ methods to C functions with __cdecl (Way 1) or include the header file (Way 2)? Other solutions?
- Related to way 2 (Include header) - how is the library loaded ? By the operating system ? If I move the library, the application cannot find the library -> Library loaded at runtime ?
- Is there a way to load a library without including a header or use it at compile time (Load library at runtime)? I read there is a way, but it isn't that easy
I hope that my questions are clear and not "noobish", otherwise please write a comment