I am trying to include the omp.h library into my project, but after looking for several answers, I still don't get success. I must warn that I'm a newbie at CMake.
Using this answer, I created the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(BRKGA_FF_Best)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
if(APPLE)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
endif()
add_executable(BRKGA_FF_Best
BRKGA.h
main.cpp
MTRand.h
Population.h
SampleDecoder.cpp
SampleDecoder.h
Structures.h
Utility.cpp
Utility.h JJSampleDecoder.h JJSampleDecoder.cpp JJmain.cpp)
target_link_libraries(BRKGA_FF_Best PRIVATE OpenMP::OpenMP_CXX)
But this generated the error fatal error: 'omp.h' file not found
.
Then, I created a new file, inspired by this answer and this answer:
cmake_minimum_required(VERSION 3.15)
project(BRKGA_FF_Best)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
find_package(OpenMP REQUIRED)
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
add_executable(BRKGA_FF_Best
BRKGA.h
main.cpp
MTRand.h
Population.h
SampleDecoder.cpp
SampleDecoder.h
Structures.h
Utility.cpp
Utility.h JJSampleDecoder.h JJSampleDecoder.cpp JJmain.cpp)
target_link_libraries(BRKGA_FF_Best PRIVATE OpenMP::OpenMP_CXX)
The above file generates an error with the following message:
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindOpenMP.cmake:477 (find_package_handle_standard_args)
CMakeLists.txt:25 (find_package)
Can anyone help me with this problem? Thanks in advance.
EDIT:
As pointed by @squareskittles, I corrected the set()
placing, but now another error came out. The new CMakeLists.txt is:
cmake_minimum_required(VERSION 3.15)
project(BRKGA_FF_Best)
set(CMAKE_CXX_STANDARD 14)
include_directories(.)
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
find_package(OpenMP REQUIRED)
add_executable(BRKGA_FF_Best
BRKGA.h
main.cpp
MTRand.h
Population.h
SampleDecoder.cpp
SampleDecoder.h
Structures.h
Utility.cpp
Utility.h JJSampleDecoder.h JJSampleDecoder.cpp JJmain.cpp)
target_link_libraries(BRKGA_FF_Best PRIVATE OpenMP::OpenMP_CXX)
And now the new error is:
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenMP_C (missing: OpenMP_omp_LIBRARY)
Call Stack (most recent call first):
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.15/Modules/FindOpenMP.cmake:477 (find_package_handle_standard_args)
CMakeLists.txt:12 (find_package)