问题描述
我正在尝试从一组目标文件中构建存档.我正在这样做
I am trying to build an archive from a collection of object files.I am doing this with
ar -rs my_archive.a foo.o bar.o other_object_files.o
.
在 linux 机器上一切正常,但是当我在我的 mac 上尝试相同的命令时,似乎只添加了一些目标文件.这会导致对应于子例程的未定义符号,比如说,other_object_files.o
.
On a linux machine everything is fine but when I try the very same command on my mac it seems like only some object files are added. This results in undefined symbols corresponding to subroutines in, let's say, other_object_files.o
.
此外,如果我尝试手动链接产生未定义符号的目标文件,我可以正确构建可执行文件.
Moreover, if I try to manually link the object files that gave rise to undefined symbols, I can properly build the executable.
那就是
ifort -o my_exec main.o other_object_files.o my_archive.a
工作正常.
我是否在这方面遗漏了 linux 和 mac 之间的一些区别?
Am I missing some difference between linux and mac regarding this?
编辑
从 nm other_object_files.o
来看,符号看起来不错,所以真的就像它们没有正确添加到存档中一样.
From nm other_object_files.o
the symbols look fine, so it is really like they where not properly added to the archive.
这里是linux和mac下my_archive.a
文件的几行(当然目标文件名和归档文件名不同)
Here are some lines of the my_archive.a
file in both linux and mac (the names of the object and archive files are different of course)
Linux:
ed_2.1-opt.a:decomp_coms.o:0000000000000000 T decomp_coms._
ed_2.1-opt.a:decomp_coms.o:0000000000000038 R decomp_coms___debug_param_const
ed_2.1-opt.a:decomp_coms.o:0000000000000030 D decomp_coms_mp_cwd_frac_
ed_2.1-opt.a:decomp_coms.o:0000000000000008 D decomp_coms_mp_decay_rate_fsc_
ed_2.1-opt.a:decomp_coms.o:0000000000000000 D decomp_coms_mp_decay_rate_ssc_
ed_2.1-opt.a:decomp_coms.o:0000000000000010 D decomp_coms_mp_decay_rate_stsc_
ed_2.1-opt.a:decomp_coms.o:0000000000000004 C decomp_coms_mp_decomp_scheme_
ed_2.1-opt.a:decomp_coms.o:0000000000000044 C decomp_coms_mp_f_labile_
苹果机:
ed_2.1-opt.a:decomp_coms.o: 0000000000000000 T _decomp_coms._
ed_2.1-opt.a:decomp_coms.o: 000000000000058c S _decomp_coms._.eh
ed_2.1-opt.a:decomp_coms.o: 0000000000000010 C _decomp_coms_mp_cwd_frac_
ed_2.1-opt.a:decomp_coms.o: 0000000000000010 C _decomp_coms_mp_decay_rate_fsc_
ed_2.1-opt.a:decomp_coms.o: 0000000000000010 C _decomp_coms_mp_decay_rate_ssc_
ed_2.1-opt.a:decomp_coms.o: 0000000000000010 C _decomp_coms_mp_decay_rate_stsc_
ed_2.1-opt.a:decomp_coms.o: 0000000000000010 C _decomp_coms_mp_decomp_scheme_
ed_2.1-opt.a:decomp_coms.o: 0000000000000050 C _decomp_coms_mp_f_labile_
编辑
也试过
libtool -static -arch_only x86_64 -o my_archive.a foo.o bar.o other_object_files.o
遵循此 SO 发布 但又没有进展.
following this SO post but again no progress.
推荐答案
问题是默认情况下显然没有添加常用符号.
The problem is that apparently common symbols are not added by default.
选项 1:
ar -rs my_archive.a foo.o bar.o other_object_files.oranlib -c my_archive.a
选项 2:
libtool -c -static -o my_archive.a foo.o bar.o other_object_files.o
这篇关于目标文件未正确添加到 mac 上的存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!