PDA

View Full Version : Compiling problem



Astrologer
10th May 2010, 10:57
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



#include "qunwrap.h"
#include "ui_qunwrap.h"

#include "snaphu_src/snaphu.h"

QUnwrap::QUnwrap(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::QUnwrap)
{
ui->setupUi(this);

int first_arg;
char** sec_arg;
start_unwrap(first_arg, sec_arg);
}

QUnwrap::~QUnwrap()
{
delete ui;
}

void QUnwrap::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


File "snaphu.h"



.....
void start_unwrap(int argc, char **argv);// main procedure
.....


File "snaphu.c"


void start_unwrap(int argc, char **argv){
//some code here
}


If I comment the line
start_unwrap(first_arg, sec_arg);, Qt compiles it.
What's wrong with it? I'm using QT Creator. Thank you for any help in advance.

faldzip
10th May 2010, 11:19
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().

Astrologer
10th May 2010, 11:33
You have to add snaphu.c to your SOURCES The file is included in the project if I get you correctly.

Chexov
10th May 2010, 11:37
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.

faldzip
10th May 2010, 11:49
The file is included in the project if I get you correctly.
Show us your .pro file.

Astrologer
10th May 2010, 12:20
.Pro file :


# -------------------------------------------------
# Project created by QtCreator 2010-05-10T13:27:26
# -------------------------------------------------
TARGET = QWrap
TEMPLATE = app
SOURCES += main.cpp \
qwrap.cpp \
snaphu_src/snaphu_util.c \
snaphu_src/snaphu_tile.c \
snaphu_src/snaphu_solver.c \
snaphu_src/snaphu_io.c \
snaphu_src/snaphu_cs2parse.c \
snaphu_src/snaphu_cs2.c \
snaphu_src/snaphu_cost.c \
snaphu_src/snaphu.c
HEADERS += qwrap.h \
snaphu_src/snaphu.h \
snaphu_src/snaphu_cs2types.h
FORMS += qwrap.ui

Astrologer
10th May 2010, 12:21
Long enough, Chexov. I recommend you swot up your English.

squidge
10th May 2010, 13:33
Your trying to use C functions from a C++ file. The function mangling will prevent this from happening.

To demangle, change:



#include "snaphu_src/snaphu.h"


to



extern "C" {
#include "snaphu_src/snaphu.h"
};


The compiler will know how to call it then.

Astrologer
11th May 2010, 07:56
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?

Astrologer
11th May 2010, 08:25
It worked. I created new project and it solved itself. Thank you again, mate. Have a nice day!