FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

linker library order

 
Post new topic   Reply to topic     Forum Index -> Build
View previous topic :: View next topic  
Author Message
kihjin



Joined: 28 Dec 2006
Posts: 18

PostPosted: Mon Jan 01, 2007 11:45 am    Post subject: linker library order Reply with quote

Linking with GCC, library order is important because that's the order in which undefined symbols are resolved.

Is there some way in bud I can ensure that libraries appear in a specific order?

Example:
Code:
kyle@frozen:~/dev$ bud timer.d @make -test
Command: '/usr/bin/dmd -c -w -version=Posix -odobjdir -L-ldl -I"/home/kyle/dev/objdir/" -I"/opt/d/phobos/" -I"/opt/d/ext/" -I"/home/kyle/dev/" timer.d '
Command: '/usr/bin/gcc -ldl objdir/timer.o -o timer -lc -lphobos -lpthread -lm'
kyle@frozen:~/dev$ bud timer.d @make     
objdir/timer.o(.data+0x6c): undefined reference to ...
collect2: ld returned 1 exit status
kyle@frozen:~/dev$ ls
Makefile  build.cfg  make.brf  objdir  timer.d

The distinct library requires -lphobos. -lphobos must appear after the library. Since timer.o requires the library, timer.o must appear before it. So we have:
"timer.o LIB -lphobos"

The following commands work as expected:
Code:
/usr/bin/gcc -o timer -ldl objdir/timer.o -lDependentLib -lphobos -lc -lpthread -lm
/usr/bin/gcc -o timer -ldl objdir/timer.o /usr/lib/libDependentLib.a -lphobos -lc -lpthread -lm


If DependentLib is moved around, the linking will fail. How can I achieve this with bud? I'm thinking of trying out pragmas. I don't know why this is so convoluted.
Back to top
View user's profile Send private message
kihjin



Joined: 28 Dec 2006
Posts: 18

PostPosted: Mon Jan 01, 2007 11:59 am    Post subject: Reply with quote

I should have waited a bit longer before posting. Then again I may not have discovered the "solution."

I added the following to my source files:
Code:
version(build) {
   pragma(link, DepedentLib);
   pragma(link, phobos);
}
This produces (working):

Command: '/usr/bin/gcc -ldl objdir/timer.o -o timer -lc -lphobos -lpthread -lm -lDepedentLib -lphobos'
Back to top
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Mon Jan 01, 2007 3:58 pm    Post subject: Re: linker library order Reply with quote

kihjin wrote:
Linking with GCC, library order is important because that's the order in which undefined symbols are resolved.

Is there some way in bud I can ensure that libraries appear in a specific order?

Not yet. This is a known issue with the gcc linker. I'll put something in place ASAP.
_________________
--
Derek
skype name: derek.j.parnell
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Build All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group