Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: running a c++ program using unix command
Date: Fri, 24 Jul 2009 12:38:02 +0000 (UTC)
Organization: SAIC
Lines: 35
Message-ID: <h4c9va$kko$1@fred.mathworks.com>
References: <gj7286$dm1$1@fred.mathworks.com> <op.unvdjikya5ziv5@uthamaa.dhcp.mathworks.com> <gkvmlm$8cq$1@fred.mathworks.com> <gqte8t$kl$1@fred.mathworks.com> <gubnjl$g4b$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1248439082 21144 172.30.248.35 (24 Jul 2009 12:38:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 24 Jul 2009 12:38:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 233605
Xref: news.mathworks.com comp.soft-sys.matlab:558098



I had this same error when trying to use a C++ program with mex:

>> mexcpp(3,4)
??? Invalid MEX-file '/home/hamilton/projects/slita/matlab_mex/mexcpp.mexa64':
/matlab2007b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required
by /home/hamilton/projects/slita/matlab_mex/mexcpp.mexa64).

Note that I was using the stock, mexcpp.cpp C++ example including in the distribution of Matlab, which I have copied to a local directory.  This error occurs when I compile using the mex command at the Unix command line, after configuration with mex --setup for gcc.

After turning on verbose in the mex command and manually compiling with various options, I narrowed it down to the -O option.  Without the -O option in the compile command, the program works in matlab.  With the -O option in the compile command, the GLIBCXX error mentioned above shows up....

So, I edited my ~/.matlab/R2007b/mexopts.sh line in the glnxa64 section:
            CXXOPTIMFLAGS='-O -DNDEBUG'
change to:
            CXXOPTIMFLAGS='-DNDEBUG'

The -O in the LDOPTIMFLAGS  doesn't matter (I assume because -O when linking doesn't really do much, it's the compiling, right?)

Why this happens I don't know.  Perhaps I need to install some "optimized" version of the libraries?   I haven't seen this particular solution documented for this error, so, I thought I'd add it for posterity.  Hope it helps someone.  I've been set back by this for months.

Background info:
My OS:  (from cat /etc/lsb-release)
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.10
DISTRIB_CODENAME=intrepid
DISTRIB_DESCRIPTION="Ubuntu 8.10"

uname -a:
Linux HOSTNAME 2.6.27-14-generic #1 SMP Wed Apr 15 19:29:46 UTC 2009 x86_64 GNU/Linux

Matlab version: 7.5.0.338 (R2007b)

Best Regards,
Mike