我在使用带有makefile和cmake的make
之前使用了一个成功编译的大型代码库。但是,现在我正在尝试使用openmp,我现在收到错误
undefined reference to `omp_get_thread_num'
undefined reference to `omp_get_num_threads'
我认为这不是CMakeLists.txt文件的问题,因为我创建了一个单独的目录并成功构建并编译了一个helloworld OpenMP程序。那是什么导致了这个错误?
我在project/src/project
编辑了CMakeLists.txt,以便包含-fopenmp
,因此它包含
set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -fopenmp")
....
TARGET_LINK_LIBRARIES(PROJECT ${OpenMP_CXX_LIBRARIES} ${PROJECT_LINK_LIBS}).
CMakeLists.txt已有行
FIND_PACKAGE( OpenMP)
if(OPENMP_FOUND)
message("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()
include_directories(SYSTEM ${OpenMP_INCLUDE_PATH})