STD linker error with Apple LLVM 4.1

后端 未结 6 463
無奈伤痛
無奈伤痛 2020-12-04 19:49

I\'ve got a large static library in C++ with bits of Objective-C originally built for iOS (armv7).

I built a OS X (64-bit Intel x86_64) version of it, but as soon as

6条回答
  •  抹茶落季
    2020-12-04 20:39

    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 
    #include 
    #include "fred.h"
    
    using namespace std;
    
    bool dofred(string &x)
    {
        cout << x << endl;
        return true;
    }
    dhcp-191:~/Development/testy/fred% cat fred.h
    
    #include 
    #include 
    
    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, std::__1::allocator >&)
    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.

提交回复
热议问题