Clion adding -lrt in cmake

已回答

Hi there,

I am having a problem with adding mqueue.h in my project. On a compiler time it gives me an error: undefined reference to `mq_open'. However, my cmake file already contains -lrt option:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lrt")

What's wrong with it or what else I have to do?

 

Thanks

0

Hi! In order to link to the rt library, you need to add something similar to the following to your CMakeLists.txt:

find_library(LIBRT rt) 
if(LIBRT)
target_link_libraries(target_name ${LIBRT})
endif()

where target_name should be replaced with your target name.

Please also read our quick CMake tutorial: https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html#libs

 

1
Avatar
Permanently deleted user

It works, thanks!

0

请先登录再写评论。