View previous topic :: View next topic |
Author |
Message |
kihjin
Joined: 28 Dec 2006 Posts: 18
|
Posted: Mon Jan 01, 2007 11:45 am Post subject: linker library order |
|
|
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 |
|
|
kihjin
Joined: 28 Dec 2006 Posts: 18
|
Posted: Mon Jan 01, 2007 11:59 am Post subject: |
|
|
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 |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Jan 01, 2007 3:58 pm Post subject: Re: linker library order |
|
|
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 |
|
|
|