MacOS 索诺玛 14.2.1、Apple M2
我正在尝试通过 CMake 编译 GMSHFEM。该程序使用 OpemMP,这导致了一些问题(因为 CMake 默认情况下找不到 HomeBrew 的 OpenMP),但最终,我通过将相应的头文件“omp.h”复制到 /usr/local/include 和库“libomp”解决了这些问题.dylib”到/usr/local/lib。
-- Found OpenMP_CXX: -Xclang -fopenmp (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
现在,CMake 可以找到 OpenMP,但在运行“make”命令时,出现错误:
[100%] Linking CXX shared library libgmshfem.dylib
ld: library 'omp' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我不明白这个。如果 omp 库位于 /usr/local/lib 中,怎么会找不到它呢?
打开CMakeCache.txt,我看到:
//CXX compiler flags for OpenMP parallelization
OpenMP_CXX_FLAGS:STRING=-Xclang -fopenmp
//Path to a file.
OpenMP_CXX_INCLUDE_DIR:PATH=/usr/local/include
//CXX compiler libraries for OpenMP parallelization
OpenMP_CXX_LIB_NAMES:STRING=libomp
//Path to a library.
OpenMP_libomp_LIBRARY:FILEPATH=/usr/local/lib/libomp.dylib
所以,看起来一切都井然有序。我做错了什么导致 clang 无法正确链接 omp 库?
通过将 GMSHFEM 的 CMake 指令指向正确的自制程序目录解决了这个问题,对我来说是:
elseif(APPLE AND EXISTS "/opt/homebrew/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
list(APPEND EXTRA_LIBS "-L/opt/homebrew/opt/libomp/lib -lomp")
set_config_option("OpenMP[Homebrew,M1]" HAVE_OPENMP)
else()
由于某种原因,我下载并放置在 /usr/local/lib 中的预编译 OpenMP 库可能是问题所在,尽管我对 OpenMP 和 CMake 的了解极其有限。
@Alex Reinking 似乎是正确的,但看起来 GMSHFEM 确实已经链接到 OpenMP_CXX。