关于iOS静态库 编译失败总结

1、"std::ios_base::Init::~Init()", referenced from

出现这样的编译问题,是需要再加进libstdc++.dylib和libstdc++.6.dylib(为6.1使用,xcode5以后默认complier也可以编译通过,本人用xcode5.1上编译,报此类问题,加上这两个类库就解决了)

2、Undefined symbols for architecture i386:
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__I_a in libUPPayPlugin.a(UPPasswordTool.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__I_a in libUPPayPlugin.a(UPPasswordTool.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(这类问题应该是真机版 和模拟器版的没区分开,导致编译失败)

3、关于链接库,要多了解iOS中的几种指令集:

目前ios的指令集有以下几种:

  • armv6
    • iPhone
    • iPhone2
    • iPhone3G
    • 第一代和第二代iPod Touch
  • armv7
    • iPhone4
    • iPhone4S
  • armv7s
    • iPhone5
    • iPhone5C
  • arm64
    • iPhone5S

 机器对指令集的支持是向下兼容的,因此armv7的指令集是可以运行在iphone5S的,只是效率没那么高而已~

Build Active Architecture Only : 只是否只编译当前适用的指令集。

================================================

 现在是2014年初,其实4和4S的用户还是蛮多的,而iphone3之类的机器几乎没有了,所以我们的指令集最低必须基于armv7.

因此,Architecture的值选择:armv7 armv7s arm64

PS:选arm64时需要最低支持5.1.1:

1,如果想自己的app在各个机器都能够最高效率的运行,则需要将Build Active Architecture Only改为NO,Valid architectures选择对应的指令集:armv7 armv7s arm64。这个会为各个指令集编译对应的代码,因此最后的 ipa体积基本翻了3倍,Release版本必须NO。

2,如果想让app体积保持最小,则现阶段应该选择Valid architectures为armv7,这样Build Active Architecture Only选YES或NO就无所谓了

了解以上这些就是打包的时候可以注意一下,防止编译时出现architectures烦人的问题。

原文链接:http://blog.csdn.net/run_fly/article/details/21036347


4、编译的时候一定要吧头文件和包正确导入,如何编译失败,首先查看Build setting 下 library search path下的.a文件路径是否正确。

5、模拟器调试时加入 .a 没选arm64的话,测试工程不能选64。architect 要保持一致,一般arm指令集可向下兼容。

下面附带stackoverflow有人分析的几个原因

http://stackoverflow.com/questions/6429494/undefined-symbols-for-architecture-armv7

The common causes for "Undefined symbols for architecture armv7" are:

    1. You import a header and do not link against the correct library. This is common, especially for headers for libraries like QuartzCore since it is not included in projects by default. To resolve:

      • Add the correct libraries in the Link Binary With Libraries section of the Build Phases.

      • If you want to add a library outside of the default search path you can include the path in theLibrary Search Paths value in the Build Settings and add 
        -l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.

    2. You copy files into your project but forgot to check the target to add the files to. To resolve:

      • Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files. If this is your issue please upvote Cortex's answer below as well.

    3. You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:

      • If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).

      • Optionally, you could create a fat static library that contains both architectures.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将C++11标准库静态链接到iOS静态库中,你需要在编译时指定相应的编译选项。具体来说,你需要在编译命令中添加以下参数: ``` -std=c++11 -stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden -miphoneos-version-min=9.0 -isysroot /path/to/iphoneos.sdk -arch armv7 -arch arm64 -isystem /path/to/iphoneos.sdk/usr/include/c++/v1 -L/path/to/iphoneos.sdk/usr/lib/ -lc++abi -lc++ -lm ``` 其中,`-std=c++11`参数指定使用C++11标准编译代码,`-stdlib=libc++`参数指定使用libc++标准库,`-fvisibility=hidden -fvisibility-inlines-hidden`参数指定隐藏符号,`-miphoneos-version-min=9.0`参数指定iOS最低版本为iOS 9.0,`-isysroot`参数指定iPhoneOS SDK的路径,`-arch`参数指定编译的架构,`-isystem`参数指定标准库头文件的路径,`-L`参数指定标准库的路径,`-lc++abi -lc++ -lm`参数指定链接的标准库。 如果你使用的是Xcode进行交叉编译,你可以在Build Settings中设置相应的编译选项。具体来说,你需要将以下编译选项添加到Other C++ Flags中: ``` -std=c++11 -stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden -miphoneos-version-min=9.0 -isysroot /path/to/iphoneos.sdk -arch armv7 -arch arm64 -isystem /path/to/iphoneos.sdk/usr/include/c++/v1 ``` 并将以下链接选项添加到Other Linker Flags中: ``` -L/path/to/iphoneos.sdk/usr/lib/ -lc++abi -lc++ -lm ``` 通过这些设置,你可以将C++11标准库静态链接到iOS静态库中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值