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

Matlab: Cannot compile mex with openmp (undefined reference)

user5551
1#
user5551 Published in September 21, 2018, 2:20 am

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!

share|improve this question
  • 1
    I don't know how mex works, but you also have to add -fopenmp to the linking step. – Zulan Dec 7 '17 at 18:23
  • @Zulan Thanks a lot! I've figured it out. – Khue Dec 7 '17 at 23:03

1 Answer 1

active oldest votes
up vote 1 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO