我收到以下错误:
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)
到目前为止,我发现像这样的错误可能是由以下原因引起的:
>文件类型为.m而不是.mm
>不使用指针在Objective-C中创建C对象
我假设它是某种交叉编译错误,但我不知道在哪里看.关于它可能是什么的想法?
编辑:
Build Settings: C++ Standard Library = libc++ C++ Language Dialect = c++0x
这些都在我的顶级项目中.包含的库也使用它们(它也引用了一个外部库,并且在将它添加到我的主项目时不再找到标题路径 – 我必须将它添加到我的主项目设置中).
编辑2:
以下是失败的构建步骤:
LD /Users/user/Library/Developer/Xcode/DerivedData/BerkeleyDBHelloWorldSimulator-bgnkrqnronvtkoaongfsdturoklb/Build/Products/Debug-iphonesimulator/BerkeleyDBHelloWorldSimulator.app/BerkeleyDBHelloWorldSimulator正常I386
cd / Users / user / 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 /用户/用户/库/开发/ Xcode / DerivedData / BerkeleyDBHelloWorldSimulator -bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator -F / Users / user / Library / Developer / Xcode / DerivedData / BerkeleyDBHelloWorldSimulator -bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator -filelist / Users / user / 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 = libc的-Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_required = 50000 -lstdc /用户/用户/资源库/开发商/ Xcode中/ DerivedData / BerkeleyDBHelloWorldSimulator-b gnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator / libBerkeleyDB.a -framework UIKit -framework Foundation -framework CoreGraphics -o / Users / user / Library / Developer / Xcode / DerivedData / BerkeleyDBHelloWorldSimulator -bgnkrqnronvtkoaongfsdturoklb / Build / Products / Debug-iphonesimulator / BerkeleyDBHelloWorldSimulator的.app / BerkeleyDBHelloWorldSimulator
解决方法
这种类型的错误是由于未成功链接到正确的libstdc .dylib(标准C库)引起的.有时,你忘记添加它,有时XCode会感到困惑.
首先,确保您确实在应用目标的设置中链接到它:它必须出现在“构建阶段”,“链接二进制文件库”中.
如果它在那里,但仍然无法链接,请检查原始构建日志中是否有XCode可能隐藏的任何警告:例如关于错误的架构.这意味着您要链接到错误的文件版本 – 例如链接到模拟器或OSX版本而不是iPhoneOSx.y.sdk目录中的版本.在过去,使用XCode 3,这很容易出错,修复它的唯一方法是尝试XCode提供的每一个不同的libstdc .dylib,直到一个工作.除了带有版本号的名称外,XCode4通常只提供一个.您通常应选择没有版本号的dylib.
确保可能链接到libstdc .dylib的所有子项目在同一位置使用相同的版本.
检查“库搜索路径”和“框架搜索路径”,查看您未自行添加的任何路径.我在这里有XCode设置旧SDK的路径,这使链接器感到困惑.