[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Linking with a static library.
From: |
Magnus Jonneryd |
Subject: |
Re: Linking with a static library. |
Date: |
22 Oct 2005 17:57:48 +0200 |
User-agent: |
KNode/0.8.2 |
Paul Pluzhnikov wrote:
> Magnus Jonneryd <magnus.jonneryd@ipbolaget.com> writes:
>
>> 5. All of the above are compiled and the object-files are inserted in to
>> a
>> library (libStuff.a). No trouble compiling.
>
> What are the compile lines you use and how are you constructing
> the libStuff.a ?
>
This is how i create the library that causes the linker error:
g++ -I../tcl_lite/include -I../LinearNumerics -I../Colour
-I../ParametricSurface -I../Utilities -ansi -pipe -O2 -Wall -W
-pedantic-errors -Werror -Wmissing-braces -Wold-style-cast -Wparentheses
-c Body.cc -o .o/Body.o
g++ -I../tcl_lite/include -I../LinearNumerics -I../Colour
-I../ParametricSurface -I../Utilities -ansi -pipe -O2 -Wall -W
-pedantic-errors -Werror -Wmissing-braces -Wold-style-cast -Wparentheses
-c BodyFactory.cc -o .o/BodyFactory.o
ar cr ../../lib/libBody.a .o/Body.o .o/BodyFactory.o
and this is the library that I'm able to link to:
g++ -I../../Colour -I../../Utilities -I../../LinearNumerics
-I../../tcl_lite/include -ansi -pipe -O2 -Wall -c LightSource.cc
-o .o/LightSource.o
g++ -I../../Colour -I../../Utilities -I../../LinearNumerics
-I../../tcl_lite/include -ansi -pipe -O2 -Wall -c LightSourceFactory.cc
-o .o/LightSourceFactory.o
g++ -I../../Colour -I../../Utilities -I../../LinearNumerics
-I../../tcl_lite/include -ansi -pipe -O2 -Wall -c PositionalLightSource.cc
-o .o/PositionalLightSource.o
g++ -I../../Colour -I../../Utilities -I../../LinearNumerics
-I../../tcl_lite/include -ansi -pipe -O2 -Wall -c PointLightSource.cc
-o .o/PointLightSource.o
ar cr ../../../lib/libLighting.a .o/LightSource.o .o/LightSourceFactory.o
.o/PositionalLightSource.o .o/PointLightSource.o
>> 6. Lastly I define a main-method, in which i instantiate an object of
>> class
>> F, and tries to link with the library, now it starts to get odd. The
>> linker says there are some undefined references in F to members in E,
>
> What is the failing link line and what is the *exact* error message?
>
g++ -I../../src/include -I../../src/tcl_lite/include -ansi -pipe -Wall -O2
-o ../simpleGrid .o/simpleGrid.o -L../../lib -L/usr/X11R6/lib/ -lBody
-lLighting -lColour -lWireframe -lTheatre -lUserInterface -lGL -lGLU
-lglut
../../lib/libTheatre.a(Theatre.o)(.text+0x92): In function
`Rendering::Theatre::render()':
: undefined reference to `Rendering::BodyFactory::render()'
../../lib/libTheatre.a(Theatre.o)(.text+0x1a7): In function
`Rendering::Theatre::Theatre()':
: undefined reference to `Rendering::BodyFactory::BodyFactory()'
../../lib/libTheatre.a(Theatre.o)(.text+0x287): In function
`Rendering::Theatre::Theatre()':
: undefined reference to `Rendering::BodyFactory::BodyFactory()'
../../lib/libTheatre.a(Theatre.o)(.text+0xe): In function
`Rendering::Theatre::addBody(ParametricSurface::Wireframe const&,
Colouring::Colour const&)':
: undefined reference to
`Rendering::BodyFactory::newBody(ParametricSurface::Wireframe const&,
Colouring::Colour const&)'
../../lib/libTheatre.a(Theatre.o)(.text+0x2e): In function
`Rendering::Theatre::removeBody(int)':
: undefined reference to `Rendering::BodyFactory::deleteObject(int)'
collect2: ld returned 1 exit status
make: *** [simpleGrid] Error 1
> Be sure main.o *preceedes* libStuff.a on the link line. Gory details
> on why this matters can be found here:
> http://webpages.charter.net/ppluzhnikov/linker.html
>
> Cheers,
I still can't figure out why I'm able to link if i instantiate an object of
class BodyFactory in my main method, if i do that everything seems to work.
Can this have something to do with that the class is a sub-class of a
template (the class LightSourceFactory is a sub-class of the same
template)? It also seems to work if I add the library libBody.a to the
linker line, after libTheatre.a, for the life of me I can't figure out why.
I've read what you wrote (linker.html) and i thought i understood it, but
apperently not. Any input would really be appreciated.
Something else that really bugs me is that if i use nm to find the symbols
in the library i get this:
nm -BC libBody.a | grep BodyFactory
76:BodyFactory.o:
84:00000550 t global constructors keyed to _ZN9Rendering11BodyFactoryC2Ev
90:00000000 T Rendering::BodyFactory::deleteObject(int)
91:00000110 T Rendering::BodyFactory::size()
92:00000060 T Rendering::BodyFactory::render()
93:000001b0 T Rendering::BodyFactory::newBody(ParametricSurface::Wireframe
const&, Colouring::Colour const&)
94:000002c0 T Rendering::BodyFactory::BodyFactory()
95:00000400 T Rendering::BodyFactory::BodyFactory()
96:00000000 W Rendering::BodyFactory::~BodyFactory()
97:00000000 W Rendering::BodyFactory::~BodyFactory()
116:00000000 V typeinfo for Rendering::BodyFactory
118:00000000 V typeinfo name for Rendering::BodyFactory
122:00000000 V vtable for Rendering::BodyFactory
Doesn't this imply that the symbol exists and that i should be able to link
to it? When i try the same thing on the library i can link to i get
something much like it (or rather i can't spot the difference), so how come
I'm only able to link to one of them but not the other?
nm -BC libLighting.a | grep LightSourceFactory
32:LightSourceFactory.o:
40:00001920 t global constructors keyed to
_ZN9Rendering8Lighting18LightSourceFactoryC2Ei
49:00000000 T Rendering::Lighting::LightSourceFactory::reposition()
50:00000440 T Rendering::Lighting::LightSourceFactory::deleteObject(int)
51:000003e0 T
Rendering::Lighting::LightSourceFactory::newLightSource(Rendering::Lighting::LightSourceType,
LinearNumerics::Point3D<double>&, Colouring::Colour&, Colouring::Colour&,
Colouring::Colour&)
52:00000240 T
Rendering::Lighting::LightSourceFactory::newPointLightSource(LinearNumerics::Point3D<double>&,
Colouring::Colour&, Colouring::Colour&, Colouring::Colour&)
53:000001a0 T Rendering::Lighting::LightSourceFactory::size()
54:00000010 T Rendering::Lighting::LightSourceFactory::render()
55:00000510 T
Rendering::Lighting::LightSourceFactory::LightSourceFactory(int)
56:00000f10 T
Rendering::Lighting::LightSourceFactory::LightSourceFactory(int)
57:00000000 W Rendering::Lighting::LightSourceFactory::~LightSourceFactory()
58:00000000 W Rendering::Lighting::LightSourceFactory::~LightSourceFactory()
82:00000000 V typeinfo for Rendering::Lighting::LightSourceFactory
84:00000000 V typeinfo name for Rendering::Lighting::LightSourceFactory
88:00000000 V vtable for Rendering::Lighting::LightSourceFactory
Phew, that's a lot of lines. Really appreciates any help you (or someone
else) can give me.
Thanks, again.
--
(Should insert humorous quotation here)