如何链接适用于iOS静态库 [英] how to link a static library for iOS

查看:854
本文介绍了如何链接适用于iOS静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了一堆的.o 文件(通过 GCC -c $ file.c中$ someotherops -o $ file.o )。现在我想将它们连接成一个静态库。

I have create a bunch of .o files (via gcc -c $file.c $someotherops -o $file.o). Now I want to link them into a static library.

我不完全相信阉我应该使用 LD GCC 这一点。在 LD 手册,它是说,我不应该直接使用它。不过,我想不通的是gcc参数来创建一个静态库。

I'm not exactly sure wether I am supposed to use ld or gcc for this. In the ld manual, it is said that I'm not supposed to use it directly. However, I cannot figure out the gcc parameters to create a static library.

我试过 LD *的.o -static -o libfoo.a中,但它抱怨很多缺失的符号(我认为所有来自libc中)的。我不明白为什么它抱怨,因为它被认为是一个静态库。我认为这将检查符号一旦我的静态库链接到一些其他的东西。

I tried ld *.o -static -o libfoo.a but it complains about a lot of missing symbols (I think all from libc). I don't understand why it complains because it is supposed to be a static library. I thought it would check for the symbols once I link that static library to some other thing.

另一件事:我用 /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld 在这里(我的目标是iOS版)。它抱怨的警告 LD:警告:使用ld_classic 。这是怎么回事?

Another thing: I use /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld here (my target is iOS). It complains with the warning ld: warning: using ld_classic. What is this about?

后来我想,也许它需要有指定的动态库。所以我加了 -lc 来反对的libc链接。但它与抱怨无法找到文件:-lc 。我加了 -L /开发/平台/ iPhoneOS.platform /开发商/软件开发工具包/ iPhoneOS5.0.sdk / usr / lib目录并有一个的libc名为.dylib

Then I thought, maybe it needs to have the dynamic libraries specified. So I added -lc to link against libc. But it complains with can't locate file for: -lc. I added -L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib and there is a libc.dylib.

任何想法?

关于 -lc 错误:我指定后, -arch的ARMv6 它逃走了。然后,它抱怨错误 libcache.dylib (必须从 libc.dylib 挂我猜是因为它没' ŧ指定它)。添加 -L ... / usr / lib目录/系统帮助。

About the -lc error: It got away after I specified -arch armv6. Then it complained about a wrong libcache.dylib (which must be linked from libc.dylib I guess because it didn't specified it). Adding -L.../usr/lib/system helped.

现在,对于每个单个的.o 文件,我得到警告 LD:警告:CPU_SUBTYPE_ARM_ALL亚型德precated 。这是怎么回事?

Now, for each single .o file, I get the warning ld: warning: CPU_SUBTYPE_ARM_ALL subtype is deprecated. What is this about?

我仍然有一堆缺少的符号,ESP:

And I still have a bunch of missing symbols, esp:

Undefined symbols for architecture armv6:
  "start", referenced from:
     -u command line option
     (maybe you meant: _PyThread_start_new_thread)
  "___udivsi3", referenced from:
      _get_len_of_range in bltinmodule.o
      _quorem in dtoa.o
      _array_resize in arraymodule.o
      _newarrayobject in arraymodule.o
      _array_fromfile in arraymodule.o
      _get_len_of_range in rangeobject.o
      _inplace_divrem1 in longobject.o
      ...
  "___unorddf2", referenced from:
      _builtin_round in bltinmodule.o
  ...

我查了一些这些符号,例如 ___ udivsi3 get_len_of_range 。该功能使用C仅算术,无需外接电话。因此,这似乎是翻译使用一些外部功能,如 ___ udivsi3 。但库这是?

I checked some of those symbols, e.g. ___udivsi3 in get_len_of_range. This function uses C arithmetic only, no external call. So this seems to be translated to use some external functions like ___udivsi3. But what libraries is this in?

-lgcc_s.1 固定大部分 ___ udivsi3 及有关失踪符号。在启动符号仍下落不明。这是什么 -u命令行选项意思?

-lgcc_s.1 fixed most of the ___udivsi3 and related missing symbols. The start symbol is still missing. What does -u command line option mean?

从这里 ,我的感觉,也许 LD 是不正确的工具,毕竟。在那里,是用来一个简单的通话AR 。而这似乎更有意义。我会检查如果这样做工作,并转变成一个回答这个问题。

From here, I got the feeling that maybe ld isn't the right tool after all. There, a simple call to aris used. And this seem to make more sense. I will check if that does work and transform this into an answer then.

在播放多转转, AR 构建一个胖静态库时朝我扔一些警告。它给了我提示使用的libtool 来代替。这就是我现在做的事情,即 libtool的-static -o libfoo.a中*的.o 。此外,我切换编译器<$c$c>/Applications/X$c$c.app/Contents/Developer/Toolchains/X$c$cDefault.xctoolchain/usr/bin/clangbut如果该事项不能肯定。

While playing more around, ar throw some warnings at me when building a fat static library. It gave me the hint to use libtool instead. That is what I'm doing now, i.e. libtool -static -o libfoo.a *.o. Also I switched the compiler to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clangbut not sure if that matters.

现在,在编译一些测试应用程序,它链接到这个静态库,我得到这些警告:

Now, at compiling some test application which links to this static library, I get these warnings:

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in __PyBuiltin_Init from /Users/az/Programmierung/python-embedded/libpython.a(bltinmodule.o). To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
ld: warning: 32-bit absolute address out of range (0x1001B70C4 max is 4GB): from _usedpools + 0x00000004 (0x001B70CC) to 0x1001B70C4
ld: warning: 32-bit absolute address out of range (0x1001B70C4 max is 4GB): from _usedpools + 0x00000000 (0x001B70CC) to 0x1001B70C4

它们是关于什么的?我不使用 -mdynamic-NO-PIC 。我还没有真正看到 _PyBuiltin_Init 我如何使用绝对地址在那里。

What are they about? I don't use -mdynamic-no-pic. I also don't really see in _PyBuiltin_Init how I use absolute addressing there.

此外,什么是超出范围,这些绝对地址呢? 修改这些都是一些非常巨大的分配。我只是删除此code现在(这是 WITH_PYMALLOC ,如果有人有兴趣在这些特定的Python内部)。

Also, what are these absolute addresses out of range about? These were some really huge allocations. I just removed this code for now (this was WITH_PYMALLOC, if anyone is interested in these specific Python internals).

当我开始在我的iPhone,我得到中止:

When I start it on my iPhone, I get the abort:

dyld的:vm_protect(0x00001000,0x00173000,假的,0×07)失败,结果= 2段__TEXT在/ var /移动/应用/ C15D9525-E7DC-4463-B05B-D39C9CA24319 / ...

当我使用 -no_pie 联系起来,它甚至不链接。它失败:

When I use -no_pie for linking, it doesn't even link. It fails with:

非法文本搬迁___stderrp在/Applications/X$c$c.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libSystem.dylib从/Users/az/Programmierung/python-embedded/libpython.a(marshal.o _read_object)为架构的ARMv7

我解决了PIE禁用,绝对寻址错误。我在命令行锵有一个 -static 。一旦我删除,警告逃走,以及dyld的/ vm_protect错误。这是它第一次实际运行一些code。

I solved the PIE disabled, Absolute addressing error. I had a -static in my command line Clang. Once I removed that, the warning got away, as well as the dyld/vm_protect error. It was the first time it actually run some code.

直到我打<一个href=\"http://stackoverflow.com/questions/11129368/strange-c-integer-inequality-comparison-result\">another有关整数比较奇怪的错误。由此该看上去更像是在他们锵构建一个bug。

Until I hit another strange error about integer comparison. Whereby this looks more like a bug in their Clang build.

推荐答案

它所有的工作了。基本上,答案是:

It all works now. Basically, the answer is:


  • 只是编译每个 *。ç文件照常 * 0 文件。唯一真正的区别是不同的GCC /铛,在 -arch的ARMv7 ,不同的SDK / include目录。

  • Just compile every *.c file as usual to *.o files. The only real difference is the different GCC/Clang, the -arch armv7, the different SDK / include dirs.

使用 libtool的-static -o libfoo.a中*的.o 来构建静态库。

就是这样。在我的问题的其他问题,只是错误地尝试头球

That's it. The other problems in my question were just wrongly headed tries.

这篇关于如何链接适用于iOS静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆