Building dynamic libraries
When building dynamic libraries, you must use a toolchain that supports dynamic linking.
To build a dynamic library, you need to use the following CMake
command:
Use of this CMake
command results in an error if the toolchain does not support dynamic linking.
You can also build a dynamic library by using the following CMake
command:
The cmake
shell command must be called with the -D BUILD_SHARED_LIBS=YES
parameter. (If the cmake
shell command is called without the -D BUILD_SHARED_LIBS=YES
parameter, a static library will be built.)
Example:
By default, the library file name matches the name of the build target defined via the parameter of the CMake
add_library()
command. The library file name can be changed by using the CMake
set_target_properties()
command. This can be done to make the library file name identical for its dynamic and static variants.
Example:
A dynamic library can be linked to other static and dynamic libraries by using the CMake
target_link_libraries()
command. In this case, static libraries must be built with the -fPIC
flag. This flag is applied when building a static library if the following CMake
command is used: