PDA

View Full Version : "Undefined reference to" error



f.tristano
2nd February 2009, 08:28
Good morning to everyone.
First of all, I work in Linux Ubuntu 8.04 with Eclipse and Qt integration.
I'm making a qt gui project named "rezclient". In my project I have to use some c functions of a library (librezShared.a) and other c functions declared in "rezCltProtocol.h" and defined in "rezCltProtocol.c". I have no problem with the library, but I have the error "undefined reference to" the functions of the rezCltProtocol.h file.

- This is the message of console:

"make debug
make -f Makefile.Debug
make[1]: Entering directory `/home/francesco/Scrivania/SERVER/eclipseWorkspace/rezclient'
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.4.3/lib -o rezclient debug/main.o debug/rezclient.o debug/moc_rezclient.o -L/usr/local/Trolltech/Qt-4.4.3/lib -lrezShared -L/home/francesco/Scrivania/SERVER/sharedSrc/Debug -lQtGui -L/usr/local/Trolltech/Qt-4.4.3/lib -L/usr/X11R6/lib -lXext -lX11 -lQtCore -lz -lm -lrt -ldl -lpthread
debug/rezclient.o: In function `rezclient::on_pushButton_clicked()':
make[1]: Leaving directory `/home/francesco/Scrivania/SERVER/eclipseWorkspace/rezclient'
/home/francesco/Scrivania/SERVER/eclipseWorkspace/rezclient/rezclient.cpp:34: undefined reference to `execCmdHeartbeat(int, unsigned int, double*)'
/home/francesco/Scrivania/SERVER/eclipseWorkspace/rezclient/rezclient.cpp:35: undefined reference to `execCmdGetClients(int, unsigned int, tRezClientList*)'
collect2: ld returned 1 exit status
make[1]: *** [rezclient] Error 1
make: *** [debug] Error 2"

- This is my .pro file:

TEMPLATE = app
TARGET = rezclient
QT += core \
gui

# Input
HEADERS += rezclient.h
SOURCES += main.cpp \
rezclient.cpp
FORMS += rezclient.ui
INCLUDEPATH += /home/francesco/Scrivania/SERVER/sharedSrc; \
/home/francesco/Scrivania/SERVER/rezClient/src;
LIBS += -lrezShared \
-L/home/francesco/Scrivania/SERVER/sharedSrc/Debug

And in my code I use this instructions to include the headers files:

extern "C"{
#include "../../sharedSrc/commondefs.h"
#include "../../sharedSrc/rezProtocol.h"
#include "../../sharedSrc/tcpsocket.h"
#include "../../rezClient/src/rezCltProtocol.h"
}

I really don't know how to solve this problem. I hope you'll help me.
Good morning.
Francesco.

Ps. Excuse me for my english.

jpn
2nd February 2009, 10:00
Where are execCmdHeartbeat() and execCmdGetClients() implemented?

caduel
2nd February 2009, 10:07
two possible errors:

* either those two functions are C (not C++!) functions: then the header was included in some C++ file without the extern "C"
(You can see that those function-calls where compiled as C++ function calls because they have signature. C-calls are just a function name (no argument types).)

* those really are C++ functions and you just do not link the lib or object file that contains them

HTH

f.tristano
2nd February 2009, 10:35
Reply to jpn:
The two functions are implemented in my rezclient.cpp file (I attached the file).

Reply to caduel:
the two functions are C functions and I included them with extern C

f.tristano
2nd February 2009, 11:00
I solved.
I just added in my .pro file the source file rezCltProtocol.c.
However, thanks.