please can anyone help me out.

I am trying to check the example provided in MATLAB documentation about how Build MEX-function from C/C++ or Fortran source code here https://ww2.mathworks.cn/help/matlab/ref/mex.html?requestedDomain=en

After creating all the directory required and copying the function yprime.c to the directory, I run this command in the matlab command

mex yprime.c

I am getting the following error

Error using mex /usr/bin/ld: cannot find -lstdc++ collect2: error: ld returned 1 exit status

What are the possible causes and solutions to this errors?


  • 1
    Is that the entire message? I am trying to understand why it would be trying to link the C++ standard library for a .c file. What version of Ubuntu and what version of MATLAB are you using, and how did you configure the C/C++ compilers for MATLAB? – steeldriver Jan 14 at 13:03
  • @steeldriver , I am using Ubuntu 16.04 and MATLAB 2015a, and my OS type is 64bit. For the compiler, I just updated the older version of the gcc to gcc 4.7 and set it as a default compiler. – Hassan Muhammad Jan 14 at 13:31

You need to install -dev packages for stdc++ library:

sudo apt install libstdc++-4.8-dev libstdc++-5-dev

and do not forget to install build-essential package.

  • I have tried your suggestion, but the error still exists. – Hassan Muhammad Jan 15 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.