This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why does linker fail to resolve dependencies within the same .a file?


On 2/28/07, Nick Clifton <nickc@redhat.com> wrote:
Hi Christian,

> /usr/bin/c++ -fPIC "CMakeFiles/simpleIO.dir/main_IO.o" -o
> simpleIO -rdynamic
> -L/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++ -lGL
> -lglut -Wl,-Bstatic -luriVision -luriVision -Wl,-Bdynamic
> -Wl,-rpath,/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++

Note: Placing "-luriVision" twice on the command line next to each other
like that will not actually gain you anything.  The only reason to
include a library more than once on a linker command line is if it
contains symbols that are referenced by files that are placed after the
first occurrence of the library on the command line.  eg:

foo.o -lbar baz.o -lbar

The second "-lbar" is only needed if baz.o includes references to
symbols that are defined in libbar.a which will not be pulled in when
resolving the references made by foo.o.

I'm not so sure that's true, because someone said that putting "bar.a" on the linker command line is pretty much identical in effect to listing, on the command line, the files that got bundled up into bar.a. So if bar.a is made up of x.o, y.o and z.o, and z.o contains a function that depends on a function in x.o, then I really do need to list bar.a twice in order to resolve that dependency. No?


> In function `uriVideoSources::ImageReader::getFrame(bool, > uriBase::RasterImage*)': > ImageReader.cpp:(.text+0x90): undefined reference to > `uriVideoSources::ImageReader_gen::getFrame_(bool, > uriBase::RasterImage*)'

> cjc@peace:~$ nm --demangle
> /home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++/liburiVision.a
> | grep outputFrame

As has already been pointed out you are greping for 'outputFrame' when
the error message you have reported was for a missing 'getFrame_'
symbol.  I assume therefore that you are also getting error messages
about a missing reference to 'outputFrame_' ?

I pasted an irrelevant example by accident, but I really am seeing the problem in question (I think). Here's the link command and my first error message from it:

cd /home/cjc/csc583-svn/uriVisionLib/trunk/SDK/Demos/C++/Basic/Simple_IO
&& /usr/bin/c++      -fPIC "CMakeFiles/simpleIO.dir/main_IO.o"   -o
simpleIO -rdynamic
-L/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++ -lGL
-lglut -Wl,-Bstatic -luriVision -luriVision -Wl,-Bdynamic
-Wl,-rpath,/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++
/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++/liburiVision.a(ImageReader.o):
In function `uriVideoSources::ImageReader::getFrame(bool,
uriBase::RasterImage*)':
ImageReader.cpp:(.text+0x90): undefined reference to
`uriVideoSources::ImageReader_gen::getFrame_(bool,
uriBase::RasterImage*)'

and here's the (hopefully) telling nm/grep statement:

cjc@peace:~$ nm --demangle
/home/cjc/csc583-svn/uriVisionLib/trunk/Development/Source/C++/liburiVision.a
| grep "uriVideoSources::ImageReader_gen::getFrame"
        U uriVideoSources::ImageReader_gen::getFrame_(bool)
        U uriVideoSources::ImageReader_gen::getFrame_(bool,
uriBase::RasterImage*)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]