我正在尝试建立一个项目,但是OpenMP出现了一些问题
这是我正在使用的cmake:
cmake_minimum_required(VERSION 2.8.6)
project(render LANGUAGES CXX)
link_directories(../core/)
include_directories(../core/)
find_package(DART REQUIRED COMPONENTS gui collision-bullet CONFIG)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(OpenMP REQUIRED) # Find the package
if (OPENGL_FOUND)
message("Found OpenGL for Mac OS")
message("OpenGL for Mac OS, include dir: ${OPENGL_INCLUDE_DIR}")
message("OpenGL for Mac OS, link libraries: ${OPENGL_gl_LIBRARY}")
else (OPENGL_FOUND)
message(FATAL_ERROR "OpenGL for Mac OS not found")
endif()
find_package(PythonLibs REQUIRED)
find_package(Boost COMPONENTS filesystem python37 numpy37)
include_directories(${DART_INCLUDE_DIRS})
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${GLUT_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
file(GLOB srcs "*.h" "*.cpp")
add_executable(render ${srcs})
target_link_libraries(render ${DART_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${GLUT_LIBRARIES} ${OpenMP_CXX_LIBRARIES} ${OpenMP_C_LIBRARIES} mss)
这是终端中的输出:
CMake Error at /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindOpenMP.cmake:477 (find_package_handle_standard_args)
render/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/vittorio/Documents/MASS-master/build/CMakeFiles/CMakeOutput.log".
See also "/Users/vittorio/Documents/MASS-master/build/CMakeFiles/CMakeError.log".
现在,如果我在执行cmake时使用以下选项,它将成功完成:
rm -rf build && mkdir build && cd build && cmake -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp" -DOpenMP_C_LIB_NAMES="omp" -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" -DOpenMP_CXX_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib -D Boost_NO_BOOST_CMAKE:BOOL=ON ..
但是当使用make -j8
构建项目时,它将无法链接到openmp。
与我的问题最接近的答案(但仍然无法解决)是: Compiling and linking against OpenMP with AppleClang on Mac OS X Mojave
有人可以帮我吗?任何帮助我将不胜感激!
PS:如果您想知道编译器信息是
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
答案 0 :(得分:1)
如here所述。链接OpenMP
的方式已更新
对于CMake 3.9+
:
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()