Std Linker Error with Apple Llvm 4.1

STD linker error with Apple LLVM 4.1

Change the standard library that is linked to use libstdc++ instead of libc++ - the problem is that the other library was compiled using the g++ mode which uses the libstdc++ library.

Consider the following sample code:

dhcp-191:~/Development/testy/fred% cat fred.cpp
#include <iostream>
#include <string>
#include "fred.h"

using namespace std;

bool dofred(string &x)
{
cout << x << endl;
return true;
}
dhcp-191:~/Development/testy/fred% cat fred.h

#include <iostream>
#include <string>

bool dofred(std::string &x);

dhcp-191:~/Development/testy/fred% clang++ -stdlib=libc++ -shared -o fred.dylib fred.cpp
dhcp-191:~/Development/testy/fred% nm fred.dylib | c++filt | grep dofred
0000000000000fa0 T dofred(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)
dhcp-191:~/Development/testy/fred% clang++ -stdlib=libstdc++ -shared -o fred.dylib fred.cpp
dhcp-191:~/Development/testy/fred% nm fred.dylib | c++filt | grep dofred
0000000000000e30 T dofred(std::string&)

You get two completely different exported symbols. When trying to use the symbol, the app that uses the same -stdlib flag will be able to link, while the app that doesn't will display a link error.

Apple LLVM Compiler Error 4.1

You need to edit the build settings for your target and update the "Prefix Header" to fix its path.

Sample Image

Apple LLVM compiler 4.1 Error

You're most likely out of disk space. Where is your build folder located? It might not be allowed to write and causing that error.

Linker Error when building Xcode project using external library

Your problem is the option: -stdlib=libc++ in the command line. It's causing a link to the wrong libc++, you need to make it -stdlib=libstdc++, as this is the stdlib that the libbmx library is compiled against.

under the Apple LLVM compiler options for the C++ standard library, select: libstdc++, or pick compiler default (which should choose libstdc++ also)

How to resolve iOS Link errors with OpenCV

Check this: (assuming you are using LLVM compiler)

Target > Build Settings > Apple LLVM Compiler 4.1 - language > C++ Standard Library

try selecting

libstdc++ (GNU C++ standard library)`  

then try switch to

libc++ (LLVM C++ standard library with C++11 support)

libstdc++ seems to work for older builds of openCV, libc++ correct for newer builds. If you have it set wrong (either way) you will see these kinds of errors.

If that isn't the cause, open the build setting side by side in each project and check every setting...

I have been battling through this recently - see my question here, answers here and github sample here. The github project includes opencv framework compiled from current source a few days ago. Right now I am putting together a multi-target sample that links to a different version of the framework if compiling under 10.6/XCode4.2 or 10.7/XCode4.4+. [On github here]

update

As @mikewoz requested, you may need to run current openCV with libstdc++ to remain compatible with other frameworks. It is possible to make a current build with libstdc++ compatibility. For details see my answer to Mike's question here:

OpenCV 2.4.3+ with libstdc++ for iOS?



Related Topics



Leave a reply



Submit