cmake - CMake:未将-lrt连接到项目
问题描述
我有一个项目,依赖于 rt 库,在运行“cmake .”之后使用 make 时显示 LIBRT 中定义的函数的未声明错误。我已经查看了与此类似的问题的大量建议,但没有一个对我有用。使用函数 check_include_files() 和 check_library_exists() 返回 TRUE,看来我使用 find_library() 成功找到了库。我什至在 link.txt 文件的末尾附加了“-lrt”。
无论如何,我有点难过并寻求一些指导。下面是我的 CMakeLists.txt 文件:
cmake_minimum_required (VERSION 3.5)
project (proj_name C)
enable_language(C)
set (SOURCES
/source/file/path
)
add_definitions (-std=c99)
add_executable (proj_name ${SOURCES})
find_library(LIBRT rt)
if(LIBRT)
target_include_directories (proj_name PUBLIC ${PROJECT_SOURCE_DIR}
/proj/includes/path #not including rt header path
${RT_INCLUDE_DIRS}
)
target_link_libraries(proj_name PUBLIC ${LIBRT})
endif(LIBRT)
set(CMAKE_C_COMPILER /usr/bin/gcc)
include(CheckIncludeFiles)
check_include_files(mqueue.h HAVE_MQUEUE_H)
if(NOT HAVE_MQUEUE_H)
message(FATAL_ERROR "mqueue.h not found")
endif(NOT HAVE_MQUEUE_H)
include(CheckLibraryExists)
check_library_exists(rt timer_gettime "" HAVE_RT)
if(NOT HAVE_RT)
message(FATAL_ERROR "timer_gettime not found")
endif(NOT HAVE_RT)
在 WSL Ubuntu 上运行。
感谢您提供任何可能的见解!
解决方案
推荐阅读
- asp.net-core - 10 秒后 ASP.NET Core 会话超时
- flutter - Flutter TextFormField 启用共享首选项
- android - 复选框和 TextInputLayout 在线性布局内未正确对齐
- r - 在没有日期的两天内计算 hh:mm 变量的中点
- python - Snakemake:仅扩展通配符的子集
- python - 修复错误:无法将输入数组从形状 (5,5) 广播到形状 (5,5,4)
- javascript - 有没有办法在 nivo 中以不同的方式缩放负 y 轴刻度
- django - Django 最佳实践模型问题(来自初学者)
- javascript - 如何在使用选项标签的反应中映射 json 响应?
- reactjs - 在搜索栏上键入时为搜索列表设置动画(React)