C ++ / Objective-C ++ Cross Compilation Errors

I have a C ++ library referenced by an Objective-C ++ project. The library compiles on its own, and the Objective-C ++ project compiles until I create the first class from the library (using the object pointer). Before using the class from my library, I had links to stl string objects that did not cause problems.

I get the following errors:

 Undefined symbols for architecture i386: "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from: __verify_callback_c in *************.a(cxx_db.o) DbEnv::_stream_message_function(__db_env const*, char const*) in *************.a(cxx_env.o) DbEnv::_stream_error_function(__db_env const*, char const*, char const*) in *************.a(cxx_env.o) "std::basic_ios<char, std::char_traits<char> >::fail() const", referenced from: __verify_callback_c in *************.a(cxx_db.o) "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int) in *************.a(cxx_db.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_dbc.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_dbt.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_env.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_mpool.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_txn.o) __static_initialization_and_destruction_0(int, int) in *************.a(cxx_lock.o) ... "std::ios_base::Init::~Init()", referenced from: ___tcf_0 in *************.a(cxx_db.o) ___tcf_0 in *************.a(cxx_dbc.o) ___tcf_0 in *************.a(cxx_dbt.o) ___tcf_0 in *************.a(cxx_env.o) ___tcf_0 in *************.a(cxx_mpool.o) ___tcf_0 in *************.a(cxx_txn.o) ___tcf_0 in *************.a(cxx_lock.o) ... ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

So far, I have found that such errors can be caused by:

  • The presence of a file type .m instead of .mm
  • Creating a C ++ object in my Objective-C ++ without using a pointer

I assume this is some kind of cross-compilation error, but I don't know where to look. Ideas about what it could be?

EDIT:

 Build Settings: C++ Standard Library = libc++ C++ Language Dialect = c++0x 

This is in my top level project. The hidden library also uses them (it also refers to an external library, and the header path is no longer found when added to my main project - I had to add it to my main project settings).

Edit 2: Here is the build result:

Ld / Users / user / Library / Developer / Xcode / DerivedData / BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator / BerkeleyDBHelloWorldSimulator.app / BerkeleyDBHelloWorldSimulator normal i386 cd / Users / username / Documents / Projects / tests / BerkeleyDBHelloWorldSimulator setenv MACOSX_DEPLOYMENT_TARGET 10.6 setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneSimulator.platform/Developer / usr / bin / clang ++ -arch i386 -isysroot / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator5.0.sdk -L / Users / user / library / developer / Xcode / DerivedData / BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsild Products / Debug-iphonesimulator -F / Users / User / Library / Developer / Xcode / Derive dData / BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator file / Users / username / Library / Developer / Xcode / DerivedData / BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsdturoklb / Build / Intermediates / BerkeleyDBHelloWorldSimulator.build / Debug-iphonesimulator / BerkeleyDBHelloWorldSimulator.build / Objects-normal /i386/BerkeleyDBHelloWorldSimulator.LinkFileList -mmacosx-version-min = 10.6 -Xlinker -objc_abi_version -Xlinker 2 -stdlib = lib ++ -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_CLIRE_CLINDREIREDQUIREDIQUIRE_LINER DerivedData / BerkeleyDBHelloWorldSimulator-b gnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator / libBerkeleyDB.a -framework UIKit -framework Foundation -framework CoreGraphics -o / Users / user / Library / Derived Xcode Data / BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator / BerkeleyDBHelloWorldSimulator.app / BerkeleyDBHelloWorldSimulator

+7
source share
2 answers

It took us some time to get closer to the solution in the comment stream, so I'm going to sum it up here:

This type of error is caused by incorrect binding to the correct libstdc++.dylib , the C ++ standard library. Sometimes you forget to add it, sometimes Xcode gets confused.

First of all, make sure that you really connect with it in your target application settings: it should appear in the "build phases", "link binary files to libraries".

If it is there, but still not connected, check the raw build log for any warnings that Xcode may hide from you: for example, about the wrong architecture. This means that you are referencing the wrong version of the file — for example, linking to a simulator or OSX version instead in the iPhoneOSx.y.sdk directory. Previously, with Xcode 3, it was really easy to make a mistake, and the only way to fix it was to try every single libstdc++.dylib that libstdc++.dylib offered while it wasn’t working. Xcode4 usually offers only one, in addition to names with version numbers. Usually you choose dylib without a version number.

Make sure all subprojects that can reference libstdc++.dylib use the same version in the same place.

Check "Library Search Paths" and "Map Search Paths" for any paths that you have not added. I set the Xcode paths to the old SDKs here, which confused the linker.

Finally, sometimes it helps to simply remove the link to libstdc++.dylib , clean up the project, exit and restart Xcode and re-add the link.

+8
source

Make sure that both code and libraries are linked to the same C ++ standard library.

+3
source

All Articles