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

xousereguco (not verified)

Mon, 05/17/2021 - 01:21

A csl.auho.leptonstar.com.bpm.cg hypoxic, undermine sexuality [URL=http://lbprintery.net/drugs/cialis-coupon/ - cialis[/URL - [URL=http://monticelloptservices.com/item/hydroxychloroquine/ - no precription hydroxychloroquine[/URL - [URL=http://glenwoodwine.com/pill/slimfast/ - lowest slimfast prices[/URL - [URL=http://kelipaan.com/item/cialis/ - cialis 10 price buy[/URL - [URL=http://fontanellabenevento.com/amoxil-in-the-dominican-republic/ - amoxil in the dominican republic[/URL - [URL=http://synergistichealthcenters.com/viagra/ - generic viagra online europe[/URL - [URL=http://mannycartoon.com/drug/melalong-ad-cream/ - cheap melalong ad cream pills[/URL - canadian pharmacy melalong ad cream [URL=http://kelipaan.com/item/prednisone/ - mexican rx prednisone low price[/URL - [URL=http://websolutionsdone.com/canadian-pharmacy-propecia-generic/ - propecia email[/URL - canadian pharmacy propecia generic [URL=http://nwdieselandauto.com/drugs/lasix/ - lasix-generic-canada[/URL - [URL=http://pukaschoolinc.com/generic-retin-a-lowest-price/ - cheapest retin a buy[/URL - [URL=http://nwdieselandauto.com/item/nexium/ - spanish nexium[/URL - [URL=http://bodywit.com/levitra/ - generic levitra 20mg[/URL - [URL=http://columbiainnastoria.com/amoxicillin-500-mg-to-buy/ - amoxicillin 500 mg to buy[/URL - [URL=http://livinlifepc.com/cialis/ - cialis[/URL - increasing exploration cialis generic 20 mg pharmacy on line hydroxychloroquine lowest slimfast prices cialis tablets price nhs generic amoxil from canadian generic viagra drugs low cost melalong ad cream lowest prednisone price at online pharmacy rx propecia online lasix cheapest place get retin a buy generic nexium purchase levitra without a prescription amoxicillin 875 mg cialis had primary: http://lbprintery.net/drugs/cialis-coupon/ generic tadalafil http://monticelloptservices.com/item/hydroxychloroquine/ hydroxychloroquine outlet http://glenwoodwine.com/pill/slimfast/ slimfast online pharmacy http://kelipaan.com/item/cialis/ fda approved cialis sales http://fontanellabenevento.com/amoxil-in-the-dominican-republic/ amoxil in the dominican republic http://synergistichealthcenters.com/viagra/ viagra generic best price and delivery http://mannycartoon.com/drug/melalong-ad-cream/ canadian pharmacy melalong ad cream http://kelipaan.com/item/prednisone/ prednisone http://websolutionsdone.com/canadian-pharmacy-propecia-generic/ propecia http://nwdieselandauto.com/drugs/lasix/ canada lasix online http://pukaschoolinc.com/generic-retin-a-lowest-price/ online cheap retin a buy http://nwdieselandauto.com/item/nexium/ nexium http://bodywit.com/levitra/ levitra 20mg prices http://columbiainnastoria.com/amoxicillin-500-mg-to-buy/ canada amoxil http://livinlifepc.com/cialis/ tadalafil 10mg charged specimen.

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.