iOS开发笔记之五——Xcode 6.0 Beta编译工程时可能遇到的问题及参考解决方案

时间:2022-08-31 14:46:50

由于开发需要,最近需要将Xcode 由5.0升级到6.0 beta版,将MAC升级到10.9.4版本后。利用Xcode 6.0编译我们的项目工程,

发现错误累累,经过一步步摸索,问题最终一一解决;现在将问题记录下来,以供参考。

(1)"_fwrite$UNIX2003"报错问题;

Undefined symbols for architecture i386:
  "_fwrite$UNIX2003", referenced from:
      _voAWB_dtx_enc_reset in libvo-amrwbenc.a(dtx.o)
      _voAWB_dtx_enc_init in libvo-amrwbenc.a(dtx.o)
      _wb_vad_reset in libvo-amrwbenc.a(wb_vad.o)
      _wb_vad_init in libvo-amrwbenc.a(wb_vad.o)
      _quant_5p_5N in libvo-amrwbenc.a(q_pulse.o)
      _quant_4p_4N in libvo-amrwbenc.a(q_pulse.o)
      _quant_6p_6N_2 in libvo-amrwbenc.a(q_pulse.o)
      ...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

对照错误来看,这是一个库链接的错误。

参考解决方案:工程内新增文件 fileadp.c  内容如下 :

    #include <stdio.h>

    FILE *fopen$UNIX2003( const char *filename, const char *mode )

    {
        return fopen(filename, mode); 
    }

    size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )

    {
        return fwrite(a, b, c, d); 
    }

*上有解释如下:

The UNIX™ conformance variants use the $UNIX2003 suffix.

Important: The work for UNIX™ conformance started in Mac OS 10.4, but was not completed until 10.5. Thus, in the 10.4 versions of libSystem.dylib, many of the conforming variant symbols (with the $UNIX2003 suffix) exist. The list is not complete, and the conforming behavior of the variant symbols may not be complete, so they should be avoided.

Because the 64-bit environment has no legacy to maintain, it was created to be UNIX™ conforming from the start, without the use of the $UNIX2003 suffix. So, for example, _fputs$UNIX2003 in 32-bit and _fputs in 64-bit will have the same conforming behavior.

看样子是64位上遗留的符号命名问题。

(2)在我们的工程项目有专业版和企业版之分,在编译企业版时,可能还会出现如下报错:

Undefined symbols for architecture i386:
  "std::istream::gcount() const", referenced from:
      sq::InSmallFile::readBuf(void*, int) in libTF.a(IOFile.o)
  "std::string::find_last_of(char, unsigned long) const", referenced from:
      getFileNameFromPath(std::string) in libTF.a(FileSrvClient.o)
  "std::string::data() const", referenced from:
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(TcpConnection.o)
      Result(boost::shared_ptr<TranFilePara_>&) in libTF.a(sqfilesrvlib.o)
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(_auto_filesrv_msg.o)
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(FileSrvClient.o)
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(FileSrvMsgCodec.o)
      sq::InSmallFile::InSmallFile(std::string) in libTF.a(IOFile.o)
      sq::OutSmallFile::OutSmallFile(std::string) in libTF.a(IOFile.o)
      ...
  "std::string::find(char const*, unsigned long) const", referenced from:
      zxing::aztec::Decoder::getEncodedData(zxing::Ref<zxing::BitArray>) in libTF.a(Decoder-387E8B3BE4AFD07D.o)
  "std::string::size() const", referenced from:
      sqnet::LogStream::operator<<(boost::thread::id const&) in libTF.a(LogStream.o)
      sqnet::LogStream::operator<<(std::string const&) in libTF.a(EventLoop.o)
      sqnet::LogStream::operator<<(std::string const&) in libTF.a(TcpClient.o)
      sqnet::LogStream::operator<<(std::string const&) in libTF.a(TcpConnection.o)
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(TcpConnection.o)
      FileSrvDownLoadRsp::lenByProtocal() const in libTF.a(_auto_filesrv_msg.o)
      sqnet::StringPiece::StringPiece(std::string const&) in libTF.a(_auto_filesrv_msg.o)
      ...
  "std::string::c_str() const", referenced from:
      boost::system::system_error::what() const in libTF.a(SQNetChannel.o)
      boost::system::system_error::what() const in libTF.a(ChannelClient.o)
      boost::system::system_error::what() const in libTF.a(ChannelClientWrapper.o)
      boost::system::system_error::what() const in libTF.a(thread-CEABBE7F4161525B.o)
      boost::system::system_error::what() const in libTF.a(mutex.o)
      boost::system::system_error::what() const in libTF.a(CurrentThread.o)
      boost::system::system_error::what() const in libTF.a(Condition.o)
      ...
  "std::string::empty() const", referenced from:
      boost::system::system_error::what() const in libTF.a(SQNetChannel.o)
      boost::system::system_error::what() const in libTF.a(ChannelClient.o)
      boost::system::system_error::what() const in libTF.a(ChannelClientWrapper.o)
      boost::system::system_error::what() const in libTF.a(thread-CEABBE7F4161525B.o)
      boost::system::system_error::what() const in libTF.a(mutex.o)
      boost::system::system_error::what() const in libTF.a(CurrentThread.o)
      boost::system::system_error::what() const in libTF.a(Condition.o)
      ...
  "std::string::length() const", referenced from:
      FileSrvDownLoadRsp::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvDownLoadReq::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvRecvBlkRsp::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvTranFileCompleteRsp::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvSendBlkRsp::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvUpLoadRsp::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      FileSrvUpLoadReq::serialize2Buf(sqnet::Buffer*) const in libTF.a(_auto_filesrv_msg.o)
      ...
  "std::string::substr(unsigned long, unsigned long) const", referenced from:
      getFileNameFromPath(std::string) in libTF.a(FileSrvClient.o)
  "std::string::compare(char const*) const", referenced from:
      CSpeedComm::CheckHttpHeader(char const*) in libMTIA.a(SpeedComm.o)
      CSpeedDecoder::DecodeQuoteUpdateData(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      CSpeedDecoder::DecodeQuoteUpdateDataNew(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      CSpeedDecoder::DecodeFormalizedTrend(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      CSpeedDecoder::DecodeFormalizedDeal(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      CSpeedDecoder::DecodeDayKLineData(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      CSpeedDecoder::DecodeMinuteKlineData(CDecodeCode&) in libMTIA.a(SpeedDecoder.o)
      ...
  "std::string::compare(std::string const&) const", referenced from:
...下面省略...

根据信息来看,编译已经通过,但是在链接时出错,我们需要手动更改我们本地的链接设置。有以下两个方法

第一、Build Settings-->Apple LLVM 5.1 - Language - C++ --> C++ Standard Library,设置为:libstdc++(GNU C++ standard library)

iOS开发笔记之五——Xcode 6.0 Beta编译工程时可能遇到的问题及参考解决方案

然后Clean工程,然后重新Build,看是否可以成功。

第二、如果上述设置仍旧不能解决你的问题,你还可以尝试Build Phases --> Link Binary With Libraries里面增加库:libstdc++.dylib
iOS开发笔记之五——Xcode 6.0 Beta编译工程时可能遇到的问题及参考解决方案

备注:上述错误,也可能是由我们自带的SDK导致,具体到其他SDK可能还会有其他的错误。

(3)参考资料:

http://blog.ready4go.com/blog/2014/06/06/xcode6-beta-build-fix/

http://*.com/questions/8732393/code-coverage-with-xcode-4-2-missing-files