Problem with linking

The engine.
Post Reply
nikkne
Posts: 19
Joined: Tue Mar 18, 2008 8:03 pm

Problem with linking

Post by nikkne »

Hi,

when I try to link against libsmile.a, I get the following errors:
/usr/lib/gcc/i486-linux-gnu/3.4.6/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o skuld /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/3.4.6/crtbegin.o -L./smile/ -L/usr/lib/gcc/i486-linux-gnu/3.4.6 -L/usr/lib/gcc/i486-linux-gnu/3.4.6 -L/usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib -L/usr/lib/gcc/i486-linux-gnu/3.4.6/../../.. -L/lib/../lib -L/usr/lib/../lib -lsmile -lJudy -lpopt -lreadline cli.o evidences.o ./smile/libsmile.a /tmp/ccvOiZm1.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/3.4.6/crtend.o /usr/lib/gcc/i486-linux-gnu/3.4.6/../../../../lib/crtn.o
/tmp/ccvOiZm1.o: In function `SkuldSystem::update_cpts(SkuldEvidenceMap&)':
/home/nikkne/skuld/skuld.cxx:157: undefined reference to `DSL_network::PartialOrdering()'
/home/nikkne/skuld/skuld.cxx:185: undefined reference to `DSL_network::GetParents(int, dsl_arcType)'
/home/nikkne/skuld/skuld.cxx:185: undefined reference to `DSL_intArray::operator=(DSL_intArray const&)'
/home/nikkne/skuld/skuld.cxx:188: undefined reference to `DSL_stringArray::IsInList(char const*) const'
<snip>

Commands used to get this output are:
g++ -g -ggdb -Wall -c -fPIC -shared -L/usr/lib -I . -o cli.o cli.cxx
g++ -g -ggdb -Wall -c -fPIC -shared -L/usr/lib -I . -o evidences.o evidences.cxx
g++ -g -ggdb -Wall -v -fPIC -I . \
-L./smile/ -lsmile -lJudy -lpopt -lreadline \
cli.o evidences.o -Xlinker ./smile/libsmile.a skuld.cxx -o skuld

I'm compiling with g++, so this error seems counterintuitive to me :(
Machine is ubuntu 7.04...
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Problem with linking

Post by shooltz[BayesFusion] »

Try moving -lsmile at the end of the g++ command line. I don't think you need -Xlinker.
nikkne
Posts: 19
Joined: Tue Mar 18, 2008 8:03 pm

Post by nikkne »

Thanks! That worked...
I included Xlinker when I was desperate what can be the cause.

So, why this works?
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

nikkne wrote:So, why this works?
This works because gcc searches symbols in libraries specified to the right of the object/source file referencing the symbol:

http://www.linuxtopia.org/online_books/ ... ro_18.html

I also think you can merge all three g++ calls into one:

Code: Select all

g++ [options] cli.cxx evidences.cxx skuld.cxx -lsmile [other libraries referenced with -l]
nikkne
Posts: 19
Joined: Tue Mar 18, 2008 8:03 pm

Post by nikkne »

Weird, yet documented :)

Thanks!
Post Reply