0

I'm trying to execute my homework in C++ with OpenMP on Mac with macOS Mojave. But it's failed. The Mac is new, so all setups are not changed. What I did:

  1. I installed Homebrew.
  2. I installed llvm (brew install llvm)
  3. I installed omp (brew install libomp)

Also, in CMakeLists.txt of the project I have

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(...)

In Terminal '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

In CLion I have this error:

[ 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

I re-read a lot of forums, but I still don’t understand what the problem may be.

tt_531
  • 51
  • 5
  • Why do you run `clang -v` and `gcc -v` in the Terminal when your `CMakeLists.txt` says your compiler is `/usr/local/opt/llvm/bin/clang++` – Mark Setchell May 09 '20 at 14:39
  • I just wanted to show you what version of clang and gcc I use, may be here my mistake is.. – tt_531 May 09 '20 at 14:45
  • The version outputs you get in the terminal are from Apple's command-line LLVM compilers, not the ones installed by Homebrew. Homebrew never installs anything outside `/usr/local` (except casks) and `clang -v` clearly reports being installed in `/Library/Developer/CommandLineTools`. – Hristo Iliev May 09 '20 at 16:50

2 Answers2

0

Be sure to call the Xcode preprocessor to handle OMP.

C++ flags should include: -Xpreprocessor -fopenmp -lomp -I/usr/local/include

LDFLAGS should include: -lomp

With cmake you may add them to your command: cmake -DCMAKE_CXX_FLAGS="-Xpreprocessor -fopenmp -lomp -I/usr/local/include" -DCMAKE_EXE_LINKER_FLAGS="-lomp" ..

or you may add them to your CMakeLists.txt

Richard Barber
  • 5,257
  • 2
  • 15
  • 26
0

After trying so many options from the following links

I had the error The CMAKE_CXX_COMPILER: g++-6 is not a full path and was not found in the PATH. So

  1. i installed GNU gcc from brew instead of Clang (gcc@12 was installed)
 brew install gcc
  1. Changed the c++ and c compilers in Preferences > Build, Execution and Development > Toolchains in CLion to the installed compilers in 1
/usr/local/bin/gcc-12 // c
/usr/local/bin/g++-12 // c++
  1. My CMakeList.txt file at this point looks like this:
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})

and it worked for me.

lordvidex
  • 3,581
  • 3
  • 17
  • 25