Andes Workshop

It is currently Tue Jul 23, 2019 12:03 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 238 times


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


Attachment:
u4.png
u4.png [ 66.16 KiB | Viewed 3126 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: No registered users and 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group