Alb*_*ert 5 gcc build ld static-libraries ios
我创建了一堆.o
文件(via gcc -c $file.c $someotherops -o $file.o
).现在我想将它们链接到一个静态库.
我不太确定我应该使用ld
或gcc
为此.在ld
手册中,据说我不应该直接使用它.但是,我无法弄清楚gcc参数来创建静态库.
我试过ld *.o -static -o libfoo.a
但它抱怨了很多丢失的符号(我想全部来自libc).我不明白它为什么抱怨,因为它应该是一个静态库.一旦我将静态库链接到其他东西,我认为它会检查符号.
另一件事:我/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld
在这里使用(我的目标是iOS).它抱怨警告ld: warning: using ld_classic
.这是关于什么的?
然后我想,也许它需要指定动态库.所以我添加-lc
了链接libc.但它抱怨can't locate file for: -lc
.我补充说-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib
,有一个libc.dylib
.
有任何想法吗?
关于-lc
错误:我指定之后就离开了-arch armv6
.然后它抱怨一个错误libcache.dylib
(libc.dylib
我猜它必须链接,因为它没有指定它).添加-L.../usr/lib/system
帮助.
现在,对于每个单独的.o
文件,我收到警告ld: warning: CPU_SUBTYPE_ARM_ALL subtype is deprecated
.这是关于什么的?
我仍然有一堆缺少的符号,尤其是:
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
...
Run Code Online (Sandbox Code Playgroud)
我查了一些这些符号,例如___udivsi3
在get_len_of_range
.此函数仅使用C算术,无需外部调用.所以这似乎被翻译为使用一些外部函数___udivsi3
.但这是什么图书馆?
-lgcc_s.1
修复了大部分___udivsi3
和相关的缺失符号.该start
符号仍下落不明.什么-u command line option
意思?
从这里开始,我觉得可能ld
毕竟不是正确的工具.在那里,使用了一个简单的调用ar
.而这似乎更有意义.我将检查它是否有效并将其转换为答案.
在玩更多游戏ar
时,在构建胖静态库时向我发出一些警告.它给了我改为使用的提示libtool
.这就是我现在正在做的事情,即libtool -static -o libfoo.a *.o
.我也把编译器切换到/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
但不确定是否重要.
现在,在编译链接到此静态库的一些测试应用程序时,我收到以下警告:
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
Run Code Online (Sandbox Code Playgroud)
他们是关于什么的?我不用-mdynamic-no-pic
.我也没有真正看到_PyBuiltin_Init
我如何在那里使用绝对寻址.
另外,这些绝对地址超出范围的是什么?编辑:这些是一些非常庞大的分配.我刚刚删除了这段代码(WITH_PYMALLOC
如果有人对这些特定的Python内部构件感兴趣的话).
当我在iPhone上启动它时,我得到了中止:
dyld: vm_protect(0x00001000, 0x00173000, false, 0x07) failed, result=2 for segment __TEXT in /var/mobile/Applications/C15D9525-E7DC-4463-B05B-D39C9CA24319/...
当我-no_pie
用于链接时,它甚至没有链接.它失败了:
Illegal text-relocation to ___stderrp in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libSystem.dylib from _read_object in /Users/az/Programmierung/python-embedded/libpython.a(marshal.o) for architecture armv7
我解决了PIE禁用,绝对寻址错误.我-static
在命令行Clang中有一个.一旦我删除了它,警告就会消失,以及dyld/vm_protect错误.这是它第一次实际运行一些代码.
直到我遇到关于整数比较的另一个奇怪错误.因此,这看起来更像是他们的Clang构建中的错误.
Alb*_*ert 12
这一切现在都有效.基本上,答案是:
只需*.c
像往常一样将每个文件编译为*.o
文件.唯一真正的区别是不同的GCC/Clang,-arch armv7
不同的SDK /包括dirs.
使用libtool -static -o libfoo.a *.o
建静态库.
而已.我的问题中的其他问题只是错误的尝试.
归档时间: |
|
查看次数: |
8278 次 |
最近记录: |