How to resolve duplicate symbol link static library

Submitted by lepton on Fri, 05/20/2016 - 11:35

Tags

首先从静态库中解压 .o 文件

ar -x lib.a

nm查看符号表  找到重复的函数符号名

nm a.o

c和c++的符号表不一样

0000000000000000 T __Z4testv //c++

0000000000000000 T test //c

 

隐藏符号 相当于加 static

ld -r a.o -unexported_symbol  __Z4testv -o c.o; rm a.o; mv c.o a.o //mac 下可使用

objcopy --localize-symbol=_Z4testv a.o
 

修改符号名称

ld -r a.o -alias __Z4testv test_c  -unexported_symbol  __Z4testv -o c.o //mac 下可使用

objcopy --redefine-sym _Z4testv=test_a a.o

如果其他 .o文件引用了这个函数 对每一个文件都要执行

find ./ -name "*.o" -exec objcopy --redefine-sym _Z4testv=test_a {} \;

 

可以给所有函数加前缀
c语言可以 函数改名变成foo_test
c++因为引入了很多系统函数 只能用上面的方法一个一个该

objcopy --prefix-symbols=foo_ a.o

重新生成静态库

ar crs lib.a *.o

Comments

Spotloan (not verified)

Thu, 11/15/2018 - 15:21

advance loan on line payday loans loans for bad credit loans in colorado springs loans online fast cash lenders direct loan program no fax payday loans loan payday personal loans with no credit check all payday lenders loan payday loans louisiana personal loans for people with bad credit personal loan for bad credit personal loans with bad credit bad credit installment loans long term payday cash advance installment loans for bad credit express cash advance online cash advance cash advance free payday loans loan get a loan with bad credit loan no credit get a loan with bad credit payday loans payday mods no interest loan payday loans no credit check online loans no credit check lending companies easy loans no credit check online loans no credit check loans online guaranteed cash til payday fast cash advance payday loan loans in charlotte nc

ousisirafi (not verified)

Thu, 11/15/2018 - 15:21

In zwq.nkev.leptonstar.com.isi.ey non-cardiogenic alcoholic antimalarials [URL=http://k3majestictheatre.com/essay-helper/ - global warming essays[/URL - [URL=http://labash2017.com/cash-advance-texas/ - cash advance[/URL - [URL=http://bookzseo.com/retin-a/ - retin a gel[/URL - [URL=http://ironvinepeekskill.com/retin-a/ - retin a buy[/URL - [URL=http://thesteki.com/viagra-pills/ - viagra[/URL - [URL=http://homemenderinc.com/rhetorical-analysis-essay/ - order essays[/URL - valve-like external, probabilistic prevented anticholinesterases.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.