Developer Blog - Inventic.eu
  • Skipper - The ORM Designer
  • VsBuilds - Parallel building
  • Pulpo - Free Skipper CLI

Tag: #clang

Qt on OSX Maverick - Undefined symbols for architecture x86_64

The problem is that starting with OSX 10.9 Apple changed default standard c++ library from libstdc++ to libc++.

Qt binary distribution compile with -stdlib=libstdc++ to be compatible with 10.6, Xcode 5 on 10.9 will select -stdlib=libc++ by default (for OS X 10.7 and better only). So symbol using classes from the standard library (like std::string in this case) will not resolve correctly at link time.

Undefined symbols for architecture x86_64:<br />
&quot;boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string&amp;lt;wchar_t, std::char_traits&amp;lt;wchar_t&amp;gt;, std::allocator&amp;lt;wchar_t&amp;gt; &amp;gt;&amp;amp;, std::codecvt&amp;lt;wchar_t, char, __mbstate_t&amp;gt; const&amp;amp;)&quot;, referenced from:<br />
boost::filesystem::path::wstring(std::codecvt&amp;lt;wchar_t, char, __mbstate_t&amp;gt; const&amp;amp;) const in filePath.o<br />
boost::filesystem::path::wstring(std::codecvt&amp;lt;wchar_t, char, __mbstate_t&amp;gt; const&amp;amp;) const in fileEnumerator.o<br />
boost::filesystem::path::wstring(std::codecvt&amp;lt;wchar_t, char, __mbstate_t&amp;gt; const&amp;amp;) const in directoryHelper.test.o<br />

So it's necessary to compile all libraries with one type of libstdc++ (or libc++). Because I need to keep 10.6 compatibility, it's necessary to compile boost and other libraries with libstdc++ dependency.

To check which library is used, use otool tool:

otool -L library.dylib<br />

As result you will get something like this (check /libc++1.dylib):

otool -L boost/lib/libboost_filesystem.dylib<br />
boost/lib/libboost_filesystem.dylib:<br />
	boost/lib/libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)<br />
	boost/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)<br />
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)<br />
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)<br />

How to fix it for boost

it's necessary to recompile boost (and don't forget to remove ./bin.v2 directory) with these params:

  ./b2 cxxflags=&quot;-stdlib=libstdc++&quot; linkflags=&quot;-stdlib=libstdc++&quot; ...<br />

and run otool again:

boost/lib/libboost_filesystem.dylib:<br />
	boost/lib/libboost_filesystem.dylib (compatibility version 0.0.0, current version 0.0.0)<br />
	boost/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)<br />
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 60.0.0)<br />
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)<br />

How to fix it for CMake libraries

In case you're using library which is built by CMake system, you  need to add following flag:

cmake -DCMAKE_CXX_FLAGS=&quot;-stdlib=libstdc++&quot;<br />

How to fix other libraries

For any other library it's necessary to pass libstdc++ flag in any available way, for example modify makefile and add :

CXXFLAGS = -stdlib=libstdc++

Second way how to fix it, compile app using latest compiler

Another way is to update mkspecs to compile for latest MacOS version, after that, compiler will be the same like compiler used on all other libraries. To do that, it's necessary to update file:

/usr/local/Qt-5.3.1/mkspecs/macx-clang/qmake.conf

and change following line:

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6

to latest 10.9 version:

QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9

More info about this process check here:

http://stackoverflow.com/questions/20342896/solved-qt5-1-qt5-2-mac-os-10-9-mavericks-xcode-5-0-2-undefined-symbols

And that's all

Hope this post saves you a lot of time I have to spent by searching these answers ;-)

External links:

05 Jan 2014

Posted by: ludek.vodicka

Programming Mac OS #Qt #mac #libstdc++ #maverick #clang