Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Hi all, I'm stuck for weeks now on this problem and I'm looking for my hero! =D The problem: I'am using autotools to compile and create an executable of my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8

    [Autotools] ld error : undefined reference to "methods"


    Hi all,

    I'm stuck for weeks now on this problem and I'm looking for my hero! =D

    The problem:
    I'am using autotools to compile and create an executable of my own applications sources but the last one can't be generated because of a link error...
    ld return : undefined reference to "methods1 name"
    undefined reference to "methods2 name"
    undefined reference to "methods3 name" and a lot more...

    Possible reason:
    My application contains some static libraries from my own building. It seems they can't be linked to my main.cpp from which I want to make the executable...
    More precisely :
    1/main.cpp calls CActivityMain::start() from libMain2.a lib
    2/CActivityMain::start() calls CAppliLayer::CAppliLayer() from libGlobal2.a

    What I've done

    In configure.ac:
    CXXFLAGS = "-O3 -I/usr/local/include -L/usr/lib/ -L/usr/local/lib/ -lMain2 -lGlobal2"

    In program/src/Makefile.am
    program_LDADD = \
    /usr/local/lib/libMain2.a\
    /usr/local/lib/libGlobal2.a\
    $(NULL)

    With a smaller size project I've succeeded bruilding my executable using the same methods...

    I've also check the location of my headers and lib. and everything was there...
    Nothing to poitn in the code, all the functions are named correctly..

    Don't hesitate to ask any information that you may need! I can provide the full configure.ac and makefile.am files on demand!
    I would appreciate any help!

    Thanks!
    Last edited by enanab; 03-04-2011 at 12:47 PM.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    Sometimes there are circular references where something in libMain2.a references something in libGlobal2.a which in turn references something in libMain2.a... This results in errors like what you are getting. The kludge for this is to link the libraries again, as in : CXXFLAGS = "-O3 -I/usr/local/include -L/usr/lib/ -L/usr/local/lib/ -lMain2 -lGlobal2 -lMain2 -lGlobal2
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Hello Rubberman =)

    thx for your quick reply!
    I've checked if my appli had some circular references and try also what you suggested anyway but nothing changes.
    I still have this error...
    May it appear because of some virtual methods use?

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    Quote Originally Posted by enanab View Post
    Hello Rubberman =)

    thx for your quick reply!
    I've checked if my appli had some circular references and try also what you suggested anyway but nothing changes.
    I still have this error...
    May it appear because of some virtual methods use?
    Well, without being able to view your source code, I really cannot say. Post it here, inside \[code\]...\[/code\] blocks (for better readability), and I might be able to say more.

    Note that I put the backslashes(\) before the [ and ] characters so the site interpretor would not think I was actually going to post code...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Actually the source code of my appli contains one hundred thousand lines (even more...) So, not sure a paste of the whole code will me more readable x)

    Instead, I am uploading here, the cpp and h files that cause this problem for you along with some screenshots ^^
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    Quote Originally Posted by enanab View Post
    Actually the source code of my appli contains one hundred thousand lines (even more...) So, not sure a paste of the whole code will me more readable x)

    Instead, I am uploading here, the cpp and h files that cause this problem for you along with some screenshots ^^
    True, but the error output from make was more revealing I think. The undefined reference to CApiLayer::CApiLayer(...) and CPcmInterface::CPcmInterface(...) constructors, et al indicate that you are either not linking the necessary libraries, are linking them in the wrong order, or there are recursive references in the libraries that are not resolved with linkage to static (vs. dynamic) libraries.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Thank you again Rubberman for your wise vision of the problem

    I have checked all this stuff already. Nothing wrong here.
    But It may be caused by a previous error I think I did not resolved correclty...
    So I put the thing here...

    Due to some virtual methods declaration and implementation, I have the error message: "Undefined reference to vtable" (see folder attached)

    I found this on an other forum :

    you would be able to progressively compile the code even if a non-pure virtual function is not defined, but to be able to link without errors, every such function must have a definition (at least a stub). and to prevent the non-creation of a v-table by the compiler, at least one of the non-pure virtual functions will have to be defined out-of-line.
    And also the usual solution in the FAQ of GCC : gcc.gnu.org/faq.html#vtables

    In order to remove the message "undefined reference to vtable", I have put all my implementation in the header files.. I know this may not be the right way to do.. If you can give any advice...I'll be pleased to learn from you!

    Thx a lot for your concern!
    Attached Files Attached Files

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    Well, in your jpeg image of your linking, there is no reference to CSystemFeedback.o where these methods are implemented. Are you compiling CSystemFeedback.cpp anywhere?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    I compiled CsystemFeedback.cpp to obain global2.a.
    So CSystemFeedback.o should be contained in global2.a library, right?
    I then try to link this global2.a with my executable so I could use the function in there.
    Do I miss something here?

  10. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,392
    Did run ranlib on the libraries? Remember what I said about circular references - if you link in a static library, at the point of linkage, only the symbols that the linker has seen so far will be resolved. If later another library or object file references some of the symbols that did NOT get linked, then you have to relink that library again. This is one reason why building shared libraries is a good idea, since all of the symbols implemented in that library will be accessible to any other code bit being linked.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •