[C++]共享内存cmake报错undefined reference to symbol ‘shm_unlink@@GLIBC_2.2.5

今日研究共享内存写得很好的CMakeLists.txt但是会报错

/usr/bin/ld: CMakeFiles/main.dir/main.cpp.o: undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/librt.so.1: 无法添加符号: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/main.dir/build.make:111: recipe for target 'main' failed
make[2]: *** [main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
于是乎网上查找资料,解决了,方法是

target_link_libraries(main ${OpenCV_LIBS} -lrt)

就是在链接库的时候加个-lrt不知道为啥要加这个库,有知道可以评论留言。不过问题是解决了。

你可能感兴趣的:(C/C++,c++,linux,开发语言)