在 Cmake 项目中指定 openmp CUDA 标志
在 cmake 项目中如何将 openmp 标志传递给 NVCC? 我的这个项目的 CMakeLists.txt 看起来像这样,但编译失败,并显示“未定义对‘omp_get_wtime’的引用”消息。
cmake_minimum_required (VERSION 2.8.2)
set (CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
${CMAKE_MODULE_PATH}
)
find_package (CUDA 4.0 REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}") endif()
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
if(UNIX)
add_definitions(-DUNIX)
endif(UNIX)
add_subdirectory(xor)
CUDA_BUILD_CLEAN_TARGET()
How can I pass openmp flag to NVCC when in a cmake project?
My CMakeLists.txt for this project looks like this, but compilation fails with "undefined reference to `omp_get_wtime'" message.
cmake_minimum_required (VERSION 2.8.2)
set (CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
${CMAKE_MODULE_PATH}
)
find_package (CUDA 4.0 REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}") endif()
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
if(UNIX)
add_definitions(-DUNIX)
endif(UNIX)
add_subdirectory(xor)
CUDA_BUILD_CLEAN_TARGET()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现将 find_package (OpenMP) 添加到前面的脚本中可以解决问题。
I just found out that adding find_package (OpenMP) to the previous script did the trick.