Andes Workshop

It is currently Fri Mar 29, 2024 4:09 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to force gcc to link an unused static library
PostPosted: Sun Aug 03, 2014 12:28 am 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
Option:
Code:
Use --whole-archive linker option.

Libraries that come after it in the command line will not have unreferenced symbols discarded. You can resume normal linking behaviour by adding --no-whole-archive after these libraries.

In your example, the command will be:

g++ -o program main.o -Wl,--whole-archive /path/to/libmylib.a
In general, it will be:

g++ -o program main.o \
    -Wl,--whole-archive -lmylib \
    -Wl,--no-whole-archive -llib1 -llib2


Reference:
http://stackoverflow.com/questions/1411 ... ic-library

Sample code
Attachment:
usercode3_4.zip [117.38 KiB]
Downloaded 742 times


Attachment:
u3.png
u3.png [ 59.3 KiB | Viewed 7089 times ]


Attachment:
u4.png
u4.png [ 66.16 KiB | Viewed 7089 times ]

The link option of usercode4
nds32le-elf-gcc -O0 -static -L../ -Wl,--whole-archive -llibcount -Wl,--no-whole-archive -T"nds32.ld" -o "usercode4.adx" ./main.o


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group