openmp not linking correctly when compiling with clang
Installing the libiomp5 package and changing -fopenmp
to -fopenmp=libiomp5
when compiling has resolved the issue.
How to compile with OpenMP in Qt on macOS?
AppleClang should work just fine. Be sure to call the preprocessor to handle OMP via the .pro
file.
macx: {
QMAKE_CXXFLAGS += -Xpreprocessor -fopenmp -lomp -I/usr/local/include
}
macx: {
QMAKE_LFLAGS += -lomp
}
macx: {
LIBS += -L /usr/local/lib /usr/local/lib/libomp.dylib
}
Xcode: Undefined symbol: _omp_get_max_threads
This is what you need to do to make a C or C++ project compile and link with OpenMP support in Xcode. Go to Build Settings in the project editor, select the project node and then the All
settings filter. Make the following changes:
- Header Search Paths (in the Search Paths group) - set to (or add tp the existing value)
/usr/local/include
, so that the compiler can find/usr/local/include/omp.h
- Library Search Paths (in the Search Paths group) - set to (or add to the existing value)
/usr/local/lib
, so that the linker can find/usr/local/lib/libomp.dylib
Select the target executable node and make the following additional changes:
- Other C Flags (in the Apple Clang - Custom Compiler Flags group) - set to (or add)
-Xclang -fopenmp
to enable processing of OpenMP pragmas by the compiler - Other Linker Flags (in the Linking group) - set to (or add)
-lomp
to enable linking with the OpenMP runtime librarylibomp.dylib
You can also make all four changes in the project node to make them project-wide or in the target node, depending on your project structure.
With C++ projects, one has to put -Xclang -fopenmp
in Other C++ Flags.
Compiling NAS Parallel Benchmarks with LLVM Clang gives error
The important error line here is:
/usr/bin/ld: cannot open output file ../bin/sp.S: No such file or directory
Since it is the output file, no such refers to the directory. Create ../bin
and it should work.
Using x86 libraries and OpenMP on macOS arm64 architecture
Using an x86 installation of brew solves the problem for me. Here is a minimal set of commands for installing x86 variants of brew and clang, and then compiling my C/C++ code:
# launch x86_64 shell
arch -x86_64 zsh
# install x86_64 variant of brew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# install x86_64 variant of clang
arch -x86_64 /usr/local/bin/brew install llvm
# compile using x86_64 variant of clang
/usr/local/opt/llvm/bin/clang++ -arch x86_64 omp_ex.cpp
The brew application is now installed in two separate locations on my machine:
# arm64 (default) location
/opt/homebrew/bin/brew
# x86_64 location
/usr/local/bin/brew
and clang is installed in three separate locations:
# Apple arm64 (default) location
/usr/bin/clang
# brew arm64 location
/opt/homebrew/opt/llvm/bin/clang
# brew x86_64 location
/usr/local/opt/llvm/bin/clang
Related Topics
Deleted Default Constructor. Objects Can Still Be Created... Sometimes
Does Std::List::Remove Method Call Destructor of Each Removed Element
Error with Multiple Definitions of Function
Move-Only Version of Std::Function
(How) How to Count the Items in an Enum
How to Remove Constness of Const_Iterator
Why Is It Undefined Behavior to Delete[] an Array of Derived Objects via a Base Pointer
How Is a Vector's Data Aligned
How to Check If an Object's Type Is a Particular Subclass in C++
Why Does Cudamalloc() Use Pointer to Pointer
What's Faster, Iterating an Stl Vector with Vector::Iterator or with At()
How to Redefine a C++ MACro Then Define It Back