g++ linking error: undefined reference

Discussion in 'C++' started by Manuel T, Mar 29, 2007.

  1. Manuel T

    Manuel T Guest

    Hello everybody,

    I'm trying to port a project from Windows+Cygwin to Linux(i'm working on a
    Debian-like: Kubuntu), but I'm facing a lot of linking problems.

    This project needs libraries xerces and gsl, more specifically libxerces-c,
    libgsl, libgslblas. The project comes with an own makefile, automatically
    generated by Eclipse cdt on Windows, on wich I made some change to fit it
    for Linux.

    Compilation step works fine, but when it tries to link tens of .o in an only
    one binary, the following error occurs:

    ../src/utils/kinematic/Kinematics.o: In function
    `Kinematics::getInvTransfMatrix(gsl_vector const*, unsigned int)':
    Kinematics.cpp:(.text+0x8d): undefined reference to
    `DirKin::getInvTransfMatrix(gsl_vector const*, unsigned int)'
    collect2: ld returned 1 exit status
    make: *** [Puma200CS.exe] Error 1

    But the above function doesn't come from any libraries. It's ust user
    defined, so it appears in Eclipse's code completion.

    How can I get rid of that?

    Here is the linker section of the makefile:

    ****************************************************************
    puma200CS: $(OBJS) $(USER_OBJS)
            @echo 'Building target: $@'
            @echo 'Invoking: GCC C++ Linker'
            g++ -L/usr/lib $(LIBS) $(OBJS) $(USER_OBJS) -o puma200CS
            @echo 'Finished building target: $@'
    ****************************************************************

    where $OBJS is a list of tens of .o and $LIBS
    is "-lgslcblas -lgsl -lxerces-c", without quotes, of course. Libraries are
    correctly installed in /usr/lib, as you can see by -L linker's flag.

    I've read somewhere that it's, maybe, a linking order question. I tried to
    change the linking order, but no way to work.

    Thanks a lot, in advance.
    --
    Emanuele Torrenti
    Linux engine 2.6.17-11-generic i686 GNU/Linux
    Manuel T, Mar 29, 2007
    #1
    1. Advertising

  2. Hello,

    Manuel T wrote:
    > g++ -L/usr/lib $(LIBS) $(OBJS) $(USER_OBJS) -o puma200CS


    g++ -L/usr/lib $(OBJS) $(USER_OBJS) $(LIBS) -o puma200CS

    Libs go always after the object files, and libs other libs depend before
    them. If you have circular dependencies between libs you have to give
    some twice.

    The question belongs into gnu.gcc.help, and is a FAQ there, here
    probably too.

    Bernd Strieder
    Bernd Strieder, Mar 29, 2007
    #2
    1. Advertising

  3. Manuel T

    Manuel T Guest

    Bernd Strieder wrote:

    > Hello,
    >
    > Manuel T wrote:
    >> g++ -L/usr/lib $(LIBS) $(OBJS) $(USER_OBJS) -o puma200CS

    >
    > g++ -L/usr/lib $(OBJS) $(USER_OBJS) $(LIBS) -o puma200CS


    Done, but same error...

    > The question belongs into gnu.gcc.help, and is a FAQ there, here
    > probably too.


    Thanks a lot... Now I'm studying autoconf & automake(to do more portable
    things). I'll post again when i fix all the stuff.

    Bye
    --
    Linux engine 2.6.17-11-generic i686 GNU/Linux
    Manuel T, Mar 29, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RU
    Replies:
    2
    Views:
    7,957
  2. Igor
    Replies:
    13
    Views:
    2,059
    Roger Leigh
    Dec 11, 2003
  3. yeah
    Replies:
    1
    Views:
    429
    Victor Bazarov
    Dec 4, 2007
  4. Replies:
    0
    Views:
    327
  5. micropentium

    Linking Error of Undefined Ref in the static lib

    micropentium, Jan 21, 2010, in forum: C Programming
    Replies:
    28
    Views:
    1,820
    gwowen
    Jan 26, 2010
Loading...

Share This Page