英文:
include_dirs for OpenMP in CMakeLists
问题
我遇到了一个启用OpenMP的项目,并且在CMakeLists.txt
文件中有以下代码行:
include_directories(${CMAKE_CUR_DIR} /usr/lib/llvm-11/include/openmp/)
我尝试将其更加通用化,如下所示:
find_package(OpenMP REQUIRED)
if (OpenMP_CXX_FOUND)
include_directories(${CMAKE_CUR_DIR) ${OpenMP_CXX_INCLUDE_DIRS})
endif()
但是OpenMP_CXX_INCLUDE_DIRS
仍然是一个空字符串,而使用include <omp.h>
的代码仍然会引发错误,我该如何处理?
我尝试了message(STATUS "${OpenMP_C_INCLUDE_DIRS}")
,但它仍然是一个空字符串。
英文:
I met a project which enable omp and has this line of code in CMakeLists.txt
:
include_directories(${CMAKE_CUR_DIR} /usr/lib/llvm-11/include/openmp/)
and I tried to make it more general like:
find_package(OpenMP REQUIRED)
if (OpenMP_CXX_FOUND)
include_directories(${CMAKE_CUR_DIR) ${OpenMP_CXX_INCLUDE_DIRS})
endif()
but the OpenMP_CXX_INCLUDE_DIRS
is still a empty string and the code using include <omp.h>
still throw an error, how can I do this?
I tried message(STATUS "${OpenMP_C_INCLUDE_DIRS}")
it still a empty string.
答案1
得分: 1
include_directories
是旧的 CMake API,现在不应该使用。
这应该足以使其工作(没有测试过,基于此 SO 问题完成):
find_package(OpenMP REQUIRED)
add_executable(YourExecutable)
target_link_libraries(YourExecutable PUBLIC OpenMP::OpenMP_CXX)
由于您使用了 REQUIRED
标志,因此不需要进行 if
检查(如果找不到库,将报告错误)。
英文:
include_directories
is old cmake API and is should not be used in now.
This should be enough to make it work (didn't test it, done base on this SO question):
find_package(OpenMP REQUIRED)
add_exectuable(YourExecutable)
target_link_libraries(YourExecutable PUBLIC OpenMP::OpenMP_CXX)
Since you are using REQUIRED
flag the if
check is not needed (error will be reported if library can't be found).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论