2

I meet an error called "Symbol not found" on matlab. The error message is in below.

Symbol not found: __ZNKSt5ctypeIcE13_M_widen_initEv
Referenced from: blabla/lib/buildW.mexmaci64
Expected in: /usr/lib/libstdc++.6.0.9.dylib

There are quite bunch of questions like me, but I never found the solution of this problem. The former threads mentioned conflicts between the updated clang and the clang used.

Here are exmaples of questions on the similar question.

  1. Need help finding Undefined Symbols
  2. Handling "dyld: lazy symbol binding failed: Symbol not found" error when nm does not find symbol
  3. https://github.com/Homebrew/homebrew-core/issues/4902

I currently installed Xcode 9.2.

And in matlab, I use MacOSX10.13.sdk like below.

>> edit ([matlabroot '/bin/maci64/mexopts/clang++_maci64.xml'])

...
...
<dirExists name="$$/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" />             
<cmdReturns name="find $$ -name MacOSX10.13.sdk" />

Also, I found that there are three files in "/usr/lib"

/usr/lib/libstdc++.6.0.9.dylib
/usr/lib/libstdc++.6.dylib
/usr/lib/libstdc++.dylib

Can anyone help me?

JonghoKim
  • 1,965
  • 7
  • 21
  • 44
  • Are you sure you are using the correct version of `clang`? Recently XCode changed the location of its compiler tools, you might have an old version still on your system and still being used. – Cris Luengo Dec 23 '17 at 15:48

1 Answers1

2

The symbol __ZNKSt5ctypeIcE13_M_widen_initEv (demangled std::ctype<char>::_M_widen_init() const) is defined in libstdc++.dylib but if you execute

nm /usr/lib/libstdc++.dylib | fgrep __ZNKSt5ctypeIcE13_M_widen_initEv

you will get

0000000000006a14 t __ZNKSt5ctypeIcE13_M_widen_initEv

as result. The t means that it's defined in the TEXT section but it's a local symbol which cannot referenced from outside the library.

Clang in Xcode uses

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib/libstdc++.tbd 

for linking instead of /usr/lib/libstdc++.dylib. This is a human readable file which contains only the name of the public symbols in libstdc++.dylib. Since the symbol above is private it is not listed in the .tbd file.

clemens
  • 16,716
  • 11
  • 50
  • 65