We would like to build a shared library with CMAKE
system. It's something like:
lib/
CMakeLists.txt
src/
CMakeLists.txt
module/
CMakeLists.txt
module1.c
foo.c
module1.c
needs some standard shared library like librt
. We have
add_library(module module1.c)
target_link_libraries(module rt)
in the module/
sub-directory. But still getting errors that stuff from librt
is not known.
If librt is linked with -lrt, then in CMake you can link it in this way:
target_link_libraries(module -lrt)
Actually what you are doing should work. If the compiler cannot find the library it may simply not be in the standard library paths. You can use the following help to specify different link_directories
(-L/some/path
parameter to the compiler).
cmake --help-command link_directories
Another useful thing you can do while debugging CMake builds is print out the commands it runs the compiler with:
make VERBOSE=1
You can then take the commands and manually tailor them to work. After that it is a matter of modifying CMAKE_C_FLAGS
/include_directories
/link_directories
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With