Results 1 to 10 of 10

Thread: Compiling problem

  1. #1
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Compiling problem

    Hi there. While compiling a file I keep on receiving two warnings and one error -
    D:\Spatial sources\projects\QUnwrap/qunwrap.cpp:14: undefined reference to `start_unwrap(int, char**)'
    D:\Spatial sources\projects\QUnwrap/qunwrap.cpp:14: undefined reference to `start_unwrap(int, char**)'
    error: collect2: ld returned 1 exit status


    Qt Code:
    1. #include "qunwrap.h"
    2. #include "ui_qunwrap.h"
    3.  
    4. #include "snaphu_src/snaphu.h"
    5.  
    6. QUnwrap::QUnwrap(QWidget *parent) :
    7. QMainWindow(parent),
    8. ui(new Ui::QUnwrap)
    9. {
    10. ui->setupUi(this);
    11.  
    12. int first_arg;
    13. char** sec_arg;
    14. start_unwrap(first_arg, sec_arg);
    15. }
    16.  
    17. QUnwrap::~QUnwrap()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void QUnwrap::changeEvent(QEvent *e)
    23. {
    24. QMainWindow::changeEvent(e);
    25. switch (e->type()) {
    26. case QEvent::LanguageChange:
    27. ui->retranslateUi(this);
    28. break;
    29. default:
    30. break;
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    File "snaphu.h"

    Qt Code:
    1. .....
    2. void start_unwrap(int argc, char **argv);// main procedure
    3. .....
    To copy to clipboard, switch view to plain text mode 

    File "snaphu.c"
    Qt Code:
    1. void start_unwrap(int argc, char **argv){
    2. //some code here
    3. }
    To copy to clipboard, switch view to plain text mode 

    If I comment the line
    Qt Code:
    1. start_unwrap(first_arg, sec_arg);
    To copy to clipboard, switch view to plain text mode 
    , Qt compiles it.
    What's wrong with it? I'm using QT Creator. Thank you for any help in advance.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Compiling problem

    Quote Originally Posted by Astrologer View Post
    Qt compiles it.
    Qt does not compile anything as it is bunch of C++ libraries, not C++ compiler (only MOC tool means Meta-Object Compiler but it is rather additional cpp files generator then compiler).

    You have to add snaphu.c to your SOURCES so it will be build with your code or if it is in some library then link against that library (LIBS qmake variable is then helpful).
    Now the C++ compiler you use can't see the body of start_unwrap().
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    Quote Originally Posted by faldżip View Post
    You have to add snaphu.c to your SOURCES
    The file is included in the project if I get you correctly.

  4. #4
    Join Date
    Apr 2010
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    How long yoy are learning programming????
    What for functions to declare global, and then it to declare in a class so also without parametres... Esteem as functions appear.

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Compiling problem

    Quote Originally Posted by Astrologer View Post
    The file is included in the project if I get you correctly.
    Show us your .pro file.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #6
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    .Pro file :
    Qt Code:
    1. # -------------------------------------------------
    2. # Project created by QtCreator 2010-05-10T13:27:26
    3. # -------------------------------------------------
    4. TARGET = QWrap
    5. TEMPLATE = app
    6. SOURCES += main.cpp \
    7. qwrap.cpp \
    8. snaphu_src/snaphu_util.c \
    9. snaphu_src/snaphu_tile.c \
    10. snaphu_src/snaphu_solver.c \
    11. snaphu_src/snaphu_io.c \
    12. snaphu_src/snaphu_cs2parse.c \
    13. snaphu_src/snaphu_cs2.c \
    14. snaphu_src/snaphu_cost.c \
    15. snaphu_src/snaphu.c
    16. HEADERS += qwrap.h \
    17. snaphu_src/snaphu.h \
    18. snaphu_src/snaphu_cs2types.h
    19. FORMS += qwrap.ui
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    Long enough, Chexov. I recommend you swot up your English.

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    Your trying to use C functions from a C++ file. The function mangling will prevent this from happening.

    To demangle, change:

    Qt Code:
    1. #include "snaphu_src/snaphu.h"
    To copy to clipboard, switch view to plain text mode 

    to

    Qt Code:
    1. extern "C" {
    2. #include "snaphu_src/snaphu.h"
    3. };
    To copy to clipboard, switch view to plain text mode 

    The compiler will know how to call it then.

  9. The following user says thank you to squidge for this useful post:

    Astrologer (11th May 2010)

  10. #9
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    Thank you so much. It worked. But another problem has appeared on the horizon - I can't debug it, you know. I've set stop points but it doesn't stop there. Is there a way to sort that out?
    Last edited by Astrologer; 11th May 2010 at 07:09.

  11. #10
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling problem

    It worked. I created new project and it solved itself. Thank you again, mate. Have a nice day!

Similar Threads

  1. Problem compiling Qt 4.6
    By dentharg in forum Installation and Deployment
    Replies: 0
    Last Post: 8th December 2009, 07:32
  2. problem compiling
    By mesman00 in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2009, 19:49
  3. Problem with compiling
    By jeanrl in forum Installation and Deployment
    Replies: 5
    Last Post: 24th March 2009, 17:15
  4. Problem in compiling
    By ja_sapienza in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2008, 15:10
  5. xlC V9 problem compiling Qt 3.3.8
    By kevinm in forum Installation and Deployment
    Replies: 0
    Last Post: 8th April 2008, 20:23

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.