【发布时间】:2021-07-07 19:35:47
【问题描述】:
我有一个项目,我需要在其中使用 NAG 库 (libnagc_nag.a) 并使用 CMake 构建项目。在我的系统上,NAG 安装在/usr/lib/NAG26。库的目录是/usr/lib/NAG26/cll6i261d/lib。
还有我的项目将使用的头文件 (nag.h, nag_stdlib.h, nagf08.h, nagx04.h)。以下是我的 CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(AnyProject VERSION 1.0)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
configure_file(AnyProject.h.in AnyProject.h)
find_library(LIB_TO_INCLUDE nagc_nag "/usr/lib/NAG26/cll6i261d/lib")
find_path(LIB_INCLUDES nag.h "/usr/lib/NAG26/cll6i261d/include")
find_path(LIB_INCLUDES nag_stdlib.h "/usr/lib/NAG26/cll6i261d/include")
find_path(LIB_INCLUDES nagf08.h "/usr/lib/NAG26/cll6i261d/include")
find_path(LIB_INCLUDES nagx04.h "/usr/lib/NAG26/cll6i261d/include")
add_executable(AnyProject ${PROJECT_SOURCE_DIR}/main.cpp)
target_include_directories(AnyProject PUBLIC ${LIB_INCLUDES})
target_include_directories(AnyProject PUBLIC
${PROJECT_BINARY_DIR}
)
target_link_libraries(AnyProject ${LIB_TO_INCLUDE})
我有几个问题
- 上面的CMakeLists.txt在构建的时候会报错:
/usr/bin/ld: warning: libifcoremt.so.5, needed by /usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libsvml.so, needed by /usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libimf.so, needed by /usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libirc.so, needed by /usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so, not found (try using -rpath or -rpath-link)
/usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so: undefined reference to `__gtq'
/usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so: undefined reference to `for_f90_index'
/usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so: undefined reference to `for_close'
/usr/lib/NAG26/cll6i261d/lib/libnagc_nag.so: undefined reference to `__intel_sse4_strspn'
.
.
.
我了解 CMake 无法找出传递依赖关系。文件 libsvml.so, libimf.so, libirc.so, libifcoremt.so.5 与添加到 target_include_directories 的 libnagc_nag.a and libnagc_nag.so 位于同一目录中。如何解决这个问题?我想我不应该在这里明确地包含传递依赖关系,或者我应该这样做吗?
-
有没有办法不指定我希望链接的
*.a库的确切路径并让 CMake 为我找到它?对于我的系统,我知道 NAG 安装在哪里,但对于其他系统,我不知道它安装在哪里。如何让上面的 CMakeLists.txt 更便携? -
有没有办法从一个目录中包含所有(必要的)头文件,而不是一个一个地包含它们(如果它们太多,这将是乏味的)?。
我是第一次使用 CMake,所以我的问题可能没有很好地形成。对于上述问题的任何一般性建议将不胜感激。
【问题讨论】:
标签: cmake