目标文件未正确添加到 Mac 上的存档中 [英] Object files not properly added to archive on mac

查看:20
本文介绍了目标文件未正确添加到 Mac 上的存档中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一组目标文件中构建档案.我正在这样做

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.afile 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 上的存档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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