Object files not properly added to archive on mac
Asked Answered
F

1

3

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.

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.

That is

ifort -o my_exec main.o other_object_files.o my_archive.a

works fine.

Am I missing some difference between linux and mac regarding this?

EDIT

From nm other_object_files.o the symbols look fine, so it is really like they where not properly added to the archive.

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_

Mac:

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_

EDIT

Tried also

libtool -static -arch_only x86_64 -o my_archive.a foo.o bar.o other_object_files.o

following this SO post but again no progress.

Formula answered 4/1, 2016 at 16:42 Comment(2)
No success even if you use "ranlib my_archive.a"? (though the man page says "ar s" is equivalent to ranlib).Lubricious
Following this I tried: ar -rs my_archive.a foo.o bar.o other_object_files.o ranlib my_archive.a but with no success.Formula
F
3

The problem is that apparently common symbols are not added by default.

Option 1:

ar -rs my_archive.a foo.o bar.o other_object_files.o ranlib -c my_archive.a

Option 2:

libtool -c -static -o my_archive.a foo.o bar.o other_object_files.o

Formula answered 5/1, 2016 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.