user906357
user906357

Reputation: 4685

Compiling C with OpenMP on my mac

I am trying to compile the code:

#include <stdio.h>
#include <omp.h>
int main(){
#pragma omp parallel
    {
        printf("%d\t%d\n",omp_get_thread_num(), omp_get_num_threads());
    }
    return 0;
}

I tried both cc -o main.exe main.c and gcc -o main.exe main.c

Both ways I get "fatal error: 'omp.h' file not found"

So I downloaded the latest version of OpenMP. Then in the terminal in the directory of the downloaded folder I typed make and then

sudo cp ./libiomp5.dylib /usr/lib/

but I am still having the same issue. How can I get this to compile?

Upvotes: 0

Views: 305

Answers (1)

tim18
tim18

Reputation: 620

You should guard the Openmp include and function calls with #if _OPENMP in order to support compiling without the openmp option (gcc -fopenmp).

Upvotes: 1

Related Questions