Results 1 to 5 of 5

Thread: Problem: Undefined reference

  1. #1
    Join Date
    Feb 2006
    Posts
    3
    Platforms
    Unix/X11

    Default Problem: Undefined reference

    I'm using an external class witch I've made myself together with a QT-form, but when I'm running make to compile the program I get errors on “Undefined reference” for every place I'm using the included class. I can't understand why...

    The way I've built up the program is that I have a project witch has a form. Inside the form I include my class, TestCls. I know that the file is included. It compiles as long as I just include it(but don't use it), and also classes refered by this class is compiled. I've also seen proof elsewhere that the class is included. But still I get this “undefined reference” everywhere I try to use it.

    Here is the code in Form.ui.h:

    #include "TestCls.h"
    void Form::testSlot(){
    TestCls tsst = TestCls();
    double nmbr = tsst.getTest();
    lineEdit_result->setText(QString::number(nmbr, 'g', 4));
    }

    Witch gives me “undefined reference” on both the creation of tsst and getTest().
    Any suggestions??


    Best Regards,
    Stian

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Problem: Undefined reference

    have you include TestCls.cpp in your *.pro file?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem: Undefined reference

    If I understand correctly, TestCls is your own class, that you created yourself, and are trying to use it in a Qt-designer created form. Undefined reference is usually a linker error, when the linker can't find the object code, or the actual implementation (definition) of classes, methods, functions, etc... (or something like that, not completely sure).

    So I am guessing you have TestCls.h and TestCls.cpp. In your TestCls you declare your classes and functions, and in the .cpp file you define them. Make sure you actually implement everything declared in your TestCls.h file in your TestCls.cpp file. Then also make sure that in your project file, TestCls.h is listed under HEADERS, and TestCls.cpp is listed under SOURCES. Then try a make clean, qmake, make.

    If this doesn't work, please provide more information, such as your .pro file, and what platform you are using and how you are building this, and more details how files are orginised.

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

  4. #4
    Join Date
    Feb 2006
    Posts
    3
    Platforms
    Unix/X11

    Default Re: Problem: Undefined reference

    Thanks both of you.
    Bojar, you are right about your assumtions, but everything is correct here.

    I think zlatko found the right answer; no, I haven't included the cpp-files in my project-file. As you probably understand I'm new to Qt, so I didn't know that I had to. I've included them now, and it works for this testexample. Now, another problem for my real program:
    I don't just have c++files. I also have some assemblyfiles, .asm. I tried to put this is with
    SOURCES += theFile.asm
    , but this didn't work. I see that also the language is specified. Can I specify a section with assembly source code files?
    LANGUAGE = ASSEMBLY
    SOURCES += theFile.asm
    , or something like this?..

    -Stian

  5. #5
    Join Date
    Feb 2006
    Posts
    3
    Platforms
    Unix/X11

    Default Re: Problem: Undefined reference

    Never mind, I figured it out.

    Instead of including the source for the assembly file I compiled it myself and included the object file, .o, by writing
    OBJECTS += theFile.o

    Now it's working. Thanks!

Similar Threads

  1. Problem with linking QT at windows.
    By zygmunt in forum Installation and Deployment
    Replies: 1
    Last Post: 21st October 2008, 21:53
  2. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  3. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 13:41
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15

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.