Reputation: 11
I'm trying to build a project and I have some issues with OpenMP
This is the cmake that I'm using:
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)
This is the output in the terminal:
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".
Now if I use the following options when executing cmake it finishes successfully:
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 ..
but when building the project with make -j8
then it fails linking to openmp.
The closest answer (but it's still not working) to my issue is: Compiling and linking against OpenMP with AppleClang on Mac OS X Mojave
Can anyone help me out on this? any help would me much appreciated!
PS: in case you're wondering the compiler infos are
-- 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
Upvotes: 1
Views: 906
Reputation: 376
As mentioned here. The way of linking OpenMP
has been updated,
For CMake 3.9+
:
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()
Upvotes: 1