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

ijezihaxu (not verified)

Tue, 10/20/2020 - 14:15

An gcg.clcm.leptonstar.com.qdx.dv oliguria, [URL=http://fitnesscabbage.com/levitra-online/ - levitra how to use[/URL - [URL=http://mannycartoon.com/sildenafil/ - generic sildenafil[/URL - [URL=http://eatingaftergastricbypass.net/erythromycin/ - erythromycin canadian pharmacy[/URL - [URL=http://calendr.net/zithromax/ - zithromax[/URL - [URL=http://gaiaenergysystems.com/priligy-dapoxetine/ - dapoxetine[/URL - priligy online [URL=http://greatlakestributarymodeling.net/levitra-20mg/ - levitra[/URL - [URL=http://iliannloeb.com/venlor/ - venlor for sale[/URL - [URL=http://eatingaftergastricbypass.net/finpecia/ - finpecia online canada[/URL - [URL=http://recipiy.com/propecia-online/ - propecia[/URL - [URL=http://umichicago.com/amoxil/ - order amoxicillin online[/URL - [URL=http://calendr.net/buy-viagra/ - viagra uk[/URL - [URL=http://center4family.com/prednisone-20-mg/ - prednisone for dogs[/URL - [URL=http://memoiselle.com/low-lyrica/ - low lyrica[/URL - lyrica [URL=http://thesteki.com/cialis-black-online/ - cialis black lowest price[/URL - [URL=http://homemenderinc.com/item/caduet/ - caduet[/URL - tumour levitra cheapest sildenafil citrate erythromycin no prescription buy zithromax priligy cost of levitra generic venlor finpecia generic canada proscar amoxicillin viagra prednisone 10 mg lyrica cialis black online caduet alteration, http://fitnesscabbage.com/levitra-online/ differences in levitra http://mannycartoon.com/sildenafil/ purchase sildenafil citrate http://eatingaftergastricbypass.net/erythromycin/ erythromycin fastest shipping http://calendr.net/zithromax/ azithromycin yahoo http://gaiaenergysystems.com/priligy-dapoxetine/ buy priligy online http://greatlakestributarymodeling.net/levitra-20mg/ levitra 20mg buy levitra online http://iliannloeb.com/venlor/ venlor for sale http://eatingaftergastricbypass.net/finpecia/ finpecia http://recipiy.com/propecia-online/ propecia online http://umichicago.com/amoxil/ 500 mg amoxicillin http://calendr.net/buy-viagra/ viagra http://center4family.com/prednisone-20-mg/ prednisone no rx http://memoiselle.com/low-lyrica/ lyrica http://thesteki.com/cialis-black-online/ cialis black lowest price http://homemenderinc.com/item/caduet/ caduet without dr prescription eplerenone: pre-existing confront xanthinuria.

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.