foges
foges

Reputation: 1536

mex + nvcc linker problems with standard library

I'm having some trouble getting Matlab mex to link to the C++ standard library on Mac OS X Maverics. The problem occurs when linking to code generated by nvcc.

All errors are related to the standard library:

Undefined symbols for architecture x86_64: "std::string::c_str() const", referenced from: ...

As far as I can tell both nvcc and mex are using the same compiler (gcc -> clang) and they both link to -lstdc++/-stdlib=libstdc++, yet it still results in a whole bunch of linker errors. If I on the other hand compile the offending instruction:

gcc -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2012a.app/extern/lib/maci64/mexFunction.map -o "solver_matlab.mexmaci64" solver_matlab.o "../solver_cu.o" "../solver_cu_link.o" -L/usr/local/cuda/lib -lcudart -lcublas -L/Applications/MATLAB_R2012a.app/bin/maci64 -lmx -lmex -lmat -lstdc++

using gcc-4.8 in terminal, then the code compiles correctly. I'm not sure how to make heads or tails of the issue, so I'd be very thankful if anyone has any suggestions.

Upvotes: 0

Views: 468

Answers (1)

foges
foges

Reputation: 1536

In case anyone stumbles upon the same problem, the solution turned out to be to pass the two additional flags to mex

LDFLAGS='\$LDFLAGS -stdlib=libstdc++' CXXFLAGS='\$CXXFLAGS -stdlib=libstdc++'

Upvotes: 0

Related Questions