Reputation: 95
I'm trying to use openMP in C with Xcode 11.4. I have installed libomp with Homebrew, and homebrew apparently installed it in: /usr/local/Cellar/libomp/10.0.0/
The code below generates a linker error: Undefined symbol: _omp_get_max_threads (likewise for get_thread_num).
#include <stdio.h>
#include "/usr/local/Cellar/libomp/10.0.0/include/omp.h"
int main () {
#pragma omp parallel
{
int threadNum = omp_get_thread_num ();
int maxThreads = omp_get_max_threads();
}
return 0; }
I tried adding usr/local/Cellar to the Header Search Paths, and including omp.h directly in my Xcode project, and adding compilation flag -openmp
, behavior does not change.
1) I coulnd't find a way to install OpenMP through Xcode directly, would it be possible / preferable?
2) Do I need to do something further for Xcode to recognize a library installed with Homebrew?
3) Why did Homebrew install the library in usr/local/Cellar, is that a bad sign?
4) Why is the missing symbol _omp_get_max_threads
and not omp_get_max_threads
?
(edit): There is also under usr/local/include the same three headers, omp.h, ompt.h and omp-tools.h, as in /usr/local/Cellar/libomp/10.0.0/. Not sure why.
Upvotes: 1
Views: 1984
Reputation: 74395
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:
/usr/local/include
, so that the compiler can find /usr/local/include/omp.h
/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:
-Xclang -fopenmp
to enable processing of OpenMP pragmas by the compiler-lomp
to enable linking with the OpenMP runtime library libomp.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.
Upvotes: 2