Home Matlab: Cannot compile mex with openmp (undefined reference)
Reply: 1

Matlab: Cannot compile mex with openmp (undefined reference)

Khue
1#
Khue Published in 2017-12-07 16:22:13Z

When compiling some C++ code in Matlab 2016b using:

mex CXXFLAGS="\$CXXFLAGS -std=c++11 -fopenmp" CXXOPTIMFLAGS='\$CXXOPTIMFLAGS -Ofast -DNDEBUG mexMyFunction.cpp

I got the following errors:

undefined reference to `omp_get_thread_num'
undefined reference to `omp_get_num_threads'

System: Ubuntu 16.04, g++ version: 5.4.0.

If I remove -fopenmp from the above command then it worked fine. Compiling directly with g++ (without mex) also worked.

Could you please help me to resolve this?

Thank you so much in advance!

Khue
2#
Khue Reply to 2017-12-07 23:03:26Z

The the following linking flags were missing:

LDOPTIMFLAGS="$LDOPTIMFLAGS -fopenmp -O2" -lgomp 

Complete command:

mex CXXFLAGS="\$CXXFLAGS -std=c++11 -fopenmp" CXXOPTIMFLAGS='\$CXXOPTIMFLAGS -Ofast -DNDEBUG' LDOPTIMFLAGS="$LDOPTIMFLAGS -fopenmp -O2" -lgomp -I"/home/khue/Libs/Eigen" mexMyFunction.cpp 

Thanks to @Zulan for his suggestion.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.262587 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO