[英]Set the OpenMP project MacOS Mojave in CLion
我正在嘗試在帶有 macOS Mojave 的 Mac 上使用 OpenMP 在 C++ 中執行我的作業。 但它失敗了。 Mac 是新的,所以所有設置都沒有改變。 我做了什么:
另外,在我擁有的項目的 CMakeLists.txt 中
cmake_minimum_required(VERSION 3.5.1)
project(...)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
set(CMAKE_CXX_COMPILER /usr/local/opt/llvm/bin/clang++)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -fopenmp -O3")
add_executable(...)
在終端“clang -v”中:
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
'gcc -v':
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
在 CLion 我有這個錯誤:
[ 25%] Linking CXX executable search
ld: unknown option: -platform_version
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [search] Error 1
make[2]: *** [CMakeFiles/search.dir/all] Error 2
make[1]: *** [CMakeFiles/search.dir/rule] Error 2
make: *** [search] Error 2
我重新閱讀了很多論壇,但我仍然不明白問題可能是什么。
一定要調用Xcode 預處理器來處理 OMP。
C++ 標志應包括: -Xpreprocessor -fopenmp -lomp -I/usr/local/include
LDFLAGS 應包括: -lomp
使用 cmake 您可以將它們添加到您的命令中: cmake -DCMAKE_CXX_FLAGS="-Xpreprocessor -fopenmp -lomp -I/usr/local/include" -DCMAKE_EXE_LINKER_FLAGS="-lomp"..
或者您可以將它們添加到您的CMakeLists.txt
從以下鏈接嘗試了這么多選項之后
我遇到了錯誤The CMAKE_CXX_COMPILER: g++-6 is not a full path and was not found in the PATH.
所以
brew install gcc@6
Preferences > Build, Execution and Development > Toolchains
in CLion 中的 c++ 和 c 編譯器更改為1
中安裝的編譯器/usr/local/Cellar/gcc@6/6.5.0_7/bin/gcc-6 // c
/usr/local/Cellar/gcc@6/6.5.0_7/bin/gcc-6 // c++
cmake_minimum_required(VERSION 3.17)
project(test)
set(CMAKE_CXX_STANDARD 11)
add_executable(test main.cpp)
target_compile_options(test PRIVATE -Wall ${OpenMP_CXX_FLAGS})
target_link_libraries(test PRIVATE ${OpenMP_CXX_FLAGS})
它對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.