Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Gcc compiler and openmp linking



I have a problem with the gcc compiler (version Red Hat 5.3.1-2) and the linking of openmp libraries.

My code includes both some OpenMP directives (so I have to compile with -fopenmp) and some MKL functions (so I link with -liomp5 -lpthread (composer_xe_2013) to use the multithreading).

So my executable is linked with both and

The multi-threading in the MKL functions works fine but the OpenMP directives (#pragma ...) are not taken into account.

Why do these two links prevent the OpenMP directives?

Below is a simple code which illustrates the problem.

#include <cstdio>
#include "omp.h"

int main(int argc, char *argv[])

#pragma omp parallel
         printf("number of threads = %d \n", omp_get_num_threads());
return 0;

When I compile with "/usr/bin/c++ OpenMP_test.cpp -o OpenMP_test -fopenmp" the OpenMP directives work.

When I compile with "/usr/bin/c++ OpenMP_test.cpp -o OpenMP_test -fopenmp -L/opt/intel/lib/intel64 -liomp5 -lpthread"  the OpenMP directives don't work.
Thanks for your help

0 Kudos
1 Reply
Black Belt

It's just plain wrong to link both libgomp and libiomp5, as the latter supports libgomp compatibility on Linux. You may need to separate your compile and link steps so as to avoid fopenmp in the latter. You might succeed in getting the link step to ignore fopenmp if you would give a more reasonable order in your command line.