Results 1 to 4 of 4

Thread: Strange compilation error : undefined reference to ...

  1. #1
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Strange compilation error : undefined reference to ...

    Hi,

    I'm using QT Creator 2.1 under Win7 and with the following code I got this error :

    error: undefined reference to `File::file_exists(QString const&) const'

    The code
    Qt Code:
    1. if ( _myfile.file_exists("test.txt") )
    To copy to clipboard, switch view to plain text mode 

    The class code
    Qt Code:
    1. bool file_exists(const QString & file) const;
    To copy to clipboard, switch view to plain text mode 

    I have the same problem with other files, by example
    Qt Code:
    1. FinancialCategory* category = ...;
    2. Product::get( category );
    3.  
    4. ...
    5.  
    6. namespace Product {
    7. bool get(Category* c)
    8. }
    To copy to clipboard, switch view to plain text mode 

    And I got this error : error: undefined reference to `Product::get(FinancialCategory* c)'

    If I do the following it works Product::get((Category*) category ) ... but it should be handled automatically ?

    Thanks for your help

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange compilation error : undefined reference to ...

    In such cases please state what are the steps you did so far:
    header included, namespace resolution, include paths checked etc...
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2010
    Posts
    95
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange compilation error : undefined reference to ...

    Thx,

    I have this (There is too much code to put everything !):

    "FinancialCategory.hh"
    Qt Code:
    1. #include "Category.hh"
    2.  
    3. class FinancialCategory : public Category { ... }
    To copy to clipboard, switch view to plain text mode 

    "Product.hh"
    Qt Code:
    1. namespace Product
    2. {
    3. bool get(Category* c);
    4. }
    To copy to clipboard, switch view to plain text mode 
    "Product.cc"
    Qt Code:
    1. namespace Product
    2. {
    3. bool get(Category* c) { ... }
    4. }
    To copy to clipboard, switch view to plain text mode 

    It is very simple code... but can't face where is the problem !!!!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Strange compilation error : undefined reference to ...

    Yes, but what have you checked so far?
    Did you check that you have included the correct header files?
    Did you check that the all the paths in your projects are correct?
    And all the other stuff you checked so that we don't have to guess if you made all the basic checks first.

    Please show the code where you use the statements with more then just the line it self, since most probably the error is in the way you have structured you code.
    You don't have to post all the code, but full relevant segments will be most helpful.
    The small pieces of code you posted give no information on what you might be doing wrong.

    error: undefined reference to `Product::get(FinancialCategory* c)'
    Wait a minute...
    Do you have a virtual method in your Category class?
    Last edited by high_flyer; 3rd December 2010 at 15:27.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 0
    Last Post: 26th June 2010, 20:47
  2. Strange Compilation issue
    By NicholasSmith in forum Newbie
    Replies: 3
    Last Post: 4th September 2009, 14:40
  3. QT 4. Compilation error
    By mansoorulhaq in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2007, 09:32
  4. strange error in compilation
    By quickNitin in forum Newbie
    Replies: 9
    Last Post: 30th August 2006, 12:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.