LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-12-2009, 10:59 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 218

Rep: Reputation: 32
Problem when link my program.....


Hello,

I have a QT programm and now I use a function in C code.
When I try to compile, I have the follow error:
Quote:
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o forminit.o forminit.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o main.o main.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o mydialog.o mydialog.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o form2.o form2.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o form3.o form3.cpp
gcc -c -pipe -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o taskman.o taskman.c
/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/bin/moc forminit.h -o moc_forminit.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o moc_forminit.o moc_forminit.cpp
/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/bin/moc mydialog.h -o moc_mydialog.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o moc_mydialog.o moc_mydialog.cpp
/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/bin/moc form2.h -o moc_form2.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o moc_form2.o moc_form2.cpp
/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/bin/moc form3.h -o moc_form3.cpp
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -m32 -mtune=geode -O2 -DQT_NO_DEBUG -DQT_SHARED -I/usr/include -I. -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/mkspecs/default -I/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/include -o moc_form3.o moc_form3.cpp
g++ -m32 -mtune=geode -Wl,-rpath,/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/lib -o prueba_ui forminit.o main.o mydialog.o form2.o form3.o taskman.o moc_forminit.o moc_mydialog.o moc_form2.o moc_form3.o -L/home/john/GeodeProject/Qt-embedded/qt-embedded-free-3.3.6/lib -L/home/john/GeodeProject/Qt-embedded/tslib-src/compilado/lib -lqte -ldl -lrt -lpthread -lts -lpcican
main.o: In function `main':
main.cpp.text+0x41): undefined reference to `init_rt_function()'
collect2: ld returned 1 exit status
make: *** [prueba_ui] Error 1

In main.cpp there is the follow code:

Quote:
#include <qapplication.h>
//#include "forminit.h"
#include "mydialog.h"
#include <qwidget.h>
#include <qnamespace.h>
#include "taskman.h"

int main( int argc, char ** argv )
{
unsigned int valor;

QApplication a( argc, argv );
//FormInit w;
MyDialog w;
valor = init_rt_function(); ---> MY PROBLEM
w.show();
w.setWindowState( 0x00000004 );
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
And I have declared the prototype in taskman.h
Quote:
#ifndef _TASKMAN_H
#define _TASKMAN_H

int init_rt_function(void);

#endif /* _TASKMAN_H */
And in taskman.c there is the code of function:

Quote:
int init_rt_function(void)
{
signum = SIGALRM;

init_signals();
init_threads();
launch_threads();

return 0;
}

I have looked for information about it, but I can not fix this problem.

Thanks a lot
 
Old 02-12-2009, 07:24 PM   #2
servat78
Member
 
Registered: Jan 2009
Posts: 100

Rep: Reputation: 17
Is taskman.c part of your QT Make file?
QT has it's own ways of building applications and my first guess is that you have not updated your .pro file and are still using the old Makefile (QT creates Makefiles based on .pro file).

Debian

Last edited by servat78; 02-19-2009 at 12:21 PM.
 
Old 02-13-2009, 03:25 AM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 218

Original Poster
Rep: Reputation: 32
Hello,
Yes, I have updated my Makefile with the new file.

But I have found my problem, in taskman.h I have changed the code with this:

Quote:
#ifndef _TASKMAN_H
#define _TASKMAN_H

#ifdef __cplusplus ----> What does mean???
extern "C" {
#endif

int init_rt_function(void);

#ifdef __cplusplus
}
#endif

#endif /* _TASKMAN_H */
I never have programmed in C++, and I do not known what does mean the new code.

Best regards
 
Old 02-13-2009, 03:30 AM   #4
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Here's a very nice explanation;
Quote:
C++ supports certain powerful but complex features that mean that
different functions and variables can have different names:
specifically, in C++ function names can be overloaded (two functions can
have the same name, but different argument signatures), and also C++
supports "namespaces", which granulate visibility in C's single global
external namespace.

To get around these problems, C++ compilers commonly "mangle" function
names: that is, the function name that appears in the global namespace
will be a string obtained in some way or other from the actual name of
the function as it appears in the code, the type and number of its
arguments, and any namespace qualifications needed to specify it.

This means that if a C++ program tries to use functions from a C
library, then there will be problems: when the C++ linker sees a
function called foobar, it will actually look in the symbol table for
something like foorbar__Fii.

To get around this, there's a way for the programmer to tell his
C++ linker that some of the functions have "C linkage", and so it
shouldn't try to mangle their names. This is achived by surrounding the
code with
extern "C" {
....
}

Sometimes, people write functions in C and then want to create a single
header that will let people use their functions either in C or C++.

To accomplish this, they make use of the fact that the macro __cplusplus
will be defined by the compiler if and only if it's compiling the
program as C++, and include the extern "C" lines conditional on the
presence of this macro. Therefore, if the file is being compiled as C
then this little bit of C++ will vanish during preprocessing, and won't
choke the C compiler.
 
Old 02-13-2009, 04:33 AM   #5
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 218

Original Poster
Rep: Reputation: 32
hello alan_ri,

Good explanation.

Thanks a lot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 08:40 AM
[gcc] how to statically link my program? G00fy Programming 5 04-16-2006 05:35 PM
How does one link a linux kernel program (example problem): pat_and_cami SUSE / openSUSE 1 02-20-2006 12:48 PM
Running a program link from Desktop paul85 Linux - Newbie 4 08-02-2005 06:40 AM
how to create a link of a program ? anindyanuri Linux - Software 7 06-19-2005 02:11 PM


All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration