您的位置:首页 > 移动开发 > IOS开发

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

2014-04-17 11:01 399 查看
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:

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 the
Library 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
.

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.

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios arm