Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Undefined reference to problem
Undefined reference to problem [message #728306] Thu, 22 September 2011 23:18 Go to next message
NMO  is currently offline NMO Friend
Messages: 9
Registered: June 2010
Junior Member
Hi,

I use Eclipse Indigo togheter with the Qt plugin. I have a Qt application with a widget that looks something like this:
/*
 * GLWidget.h
 *
 *  Created on: Sep 22, 2011
 *      Author: martin
 */

#ifndef GLWIDGET_H_
#define GLWIDGET_H_
#include <QGLWidget>
#include "GraphicSystem.h"
class GLWidget : public QGLWidget, public GraphicSystem {
public:
	GLWidget(QWidget *parent);
	virtual void render();
	//virtual ~GLWidget();
protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
};

#endif /* GLWIDGET_H_ */


The class GraphicSystem is part of another project. I tried to reference it but when I compile my application I get following error:

What do I have to do to get it running?
make debug 
make -f Makefile.Debug
make[1]: Entering directory `/home/martin/workspace/IntersectionTesting_QTGUI'
g++ -Wl,-rpath,/home/martin/QtSDK/Desktop/Qt/474/gcc/lib -o IntersectionTesting_QTGUI debug/GLWidget.o debug/main.o debug/intersectiontesting_qtgui.o debug/moc_intersectiontesting_qtgui.o    -L/home/martin/QtSDK/Desktop/Qt/474/gcc/lib -L/usr/X11R6/lib -lQtOpenGL -lQtGui -lQtCore -lGLU -lGL -lpthread 
debug/GLWidget.o: In function `GraphicSystem':
make[1]: Leaving directory `/home/martin/workspace/IntersectionTesting_QTGUI'
/home/martin/workspace/IntersectionTesting_QTGUI/../IntersectionTesting/src/GraphicSystem.h:11: undefined reference to `WorldChangedModel::WorldChangedModel()'
collect2: ld returned 1 exit status
make[1]: *** [IntersectionTesting_QTGUI] Error 1
make: *** [debug] Error 2
Re: Undefined reference to problem [message #728372 is a reply to message #728306] Fri, 23 September 2011 06:54 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
That's a linker error. Your application needs the class GraphicSystem to be linked against. Is this class in a lib?

Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Undefined reference to problem [message #728483 is a reply to message #728372] Fri, 23 September 2011 10:47 Go to previous messageGo to next message
NMO  is currently offline NMO Friend
Messages: 9
Registered: June 2010
Junior Member
No it's not.
Under Project -> Properties -> C/C++ Project Paths i added the project with the GraphicSystem class.

And under Project -> Properties -> C/C++ Include Paths and Symbols i added the project too.

I don't know what I could do further.
Re: Undefined reference to problem [message #729257 is a reply to message #728306] Sun, 25 September 2011 16:22 Go to previous messageGo to next message
NMO  is currently offline NMO Friend
Messages: 9
Registered: June 2010
Junior Member
Has really nobody an idea?
Re: Undefined reference to problem [message #729420 is a reply to message #728483] Mon, 26 September 2011 07:00 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
NMO wrote on Fri, 23 September 2011 12:47
No it's not.
Under Project -> Properties -> C/C++ Project Paths i added the project with the GraphicSystem class.

And under Project -> Properties -> C/C++ Include Paths and Symbols i added the project too.

I don't know what I could do further.

These settings are only for the indexer. You have to compile GraphicSystem.cpp and link the resulting object file against your application. As you have a Qt application I guess you are using a .pro file. There you have to add GraphicSystem.cpp as a SOURCE file (and the header, too).
Why is GraphicSystem class in a separate project? I don't know your project structure to give you more help.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Undefined reference to problem [message #729979 is a reply to message #729420] Tue, 27 September 2011 12:04 Go to previous messageGo to next message
NMO  is currently offline NMO Friend
Messages: 9
Registered: June 2010
Junior Member
I think that this problem hat nothing to do with Qt.

I created 2 projects: test1 and test2

Each project has one class: testclass and A

project test1:
testclass.h:
#ifndef TESTCLASS_H_
#define TESTCLASS_H_

class testclass {
public:
	testclass();
	virtual ~testclass();
};

#endif /* TESTCLASS_H_ */


testclass.cpp
#include "testclass.h"

testclass::testclass() {
}

testclass::~testclass() {
}


project test2:
A.h:
#ifndef A_H_
#define A_H_
#include "B.h"
#include "testclass.h"
class A {
public:
	A();
	virtual ~A();
	virtual void render() = 0;
	testclass t;
};

#endif /* A_H_ */


A.cpp:
#include "A.h"

A::A() {
	// TODO Auto-generated constructor stub

}

A::~A() {
	// TODO Auto-generated destructor stub
}


In class A i've created an instance of testclass.
When I run project test2, i get following error:

./src/A.o: In function `A':
/home/martin/workspace/test2/Debug/../src/A.cpp:10: undefined reference to `testclass::testclass()'
./src/A.o: In function `~A':
/home/martin/workspace/test2/Debug/../src/A.cpp:15: undefined reference to `testclass::~testclass()'


Under Project -> Properties -> GCC C++ Linker -> Libraries i've added the path to the object file of testclass.

So why the hell isn't it working?
Re: Undefined reference to problem [message #730418 is a reply to message #729979] Wed, 28 September 2011 11:10 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
testclass.cpp is not part of project test2. Therefore, it is nor compiled neither linked. That is indeed not a problem of Qt but of your project setup.

What you have to do:
1) project test2 must reference project1, in Project Properties-> C/C++ General-> Paths and Symbols->References
=> testclass.cpp is compiled when you build project test2

2) Project Properties-> C/C++ Build->Tool Settings
GCC C++ Linker->Miscellaneous: In Other Objects add testclass.o (use workspace path)


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Undefined reference to problem [message #730691 is a reply to message #730418] Wed, 28 September 2011 21:40 Go to previous messageGo to next message
NMO  is currently offline NMO Friend
Messages: 9
Registered: June 2010
Junior Member
Yes that worked.

Now it just has to work for Qt plugin and i would be happy. Smile
Qt plugin has no option for linker settings.

Edit: I've found the solution now.
Just add the objects file in Makefile.Debug or Makefile.Release
Thats all.

[Updated on: Wed, 28 September 2011 22:09]

Report message to a moderator

Re: Undefined reference to problem [message #730786 is a reply to message #730691] Thu, 29 September 2011 07:29 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
NMO wrote on Wed, 28 September 2011 23:40
Yes that worked.

Now it just has to work for Qt plugin and i would be happy. Smile
Qt plugin has no option for linker settings.

Edit: I've found the solution now.
Just add the objects file in Makefile.Debug or Makefile.Release
Thats all.

I would not edit the Makefiles manually. The next time you change something in the project setup your Makefiles are recreated and your adjustments are lost. As I told you before in case of Qt you should add testclass.cpp and testclass.h to your .pro file. The Qt plugin will call then qmake to create the Makefiles from the .pro file.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Undefined reference to problem [message #787956 is a reply to message #730786] Wed, 01 February 2012 07:03 Go to previous message
Faez Shingeri is currently offline Faez ShingeriFriend
Messages: 2
Registered: January 2012
Junior Member
I am using eclipse IDE with MinGw installed. I copied all the libxl C libraries into the C:\MinGw\include but when I try to compile the program, I get the below errors :

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:14: undefined reference to `xlCreateBookCA'

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:17: undefined reference to `xlBookAddSheetA'

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:20: undefined reference to `xlSheetWriteStrA'

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:21: undefined reference to `xlSheetWriteNumA'

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:23: undefined reference to `xlBookSaveA'

D:\Faez\Software & Download\ExcelFilePgm\Debug/../MyFirstExcelFile.c:24: undefined reference to `xlBookReleaseA'

collect2: ld returned 1 exit status

Build error occurred, build is stopped

Time consumed: 515 ms.



Here is the program I am trying to compile:

#include <stdio.h>
#include <libxl.h>


int main()
{
BookHandle book = xlCreateBook(); // xlCreateXMLBook()
if(book)
{
SheetHandle sheet = xlBookAddSheet(book, L"Sheet1", 0);
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Hello, World !", NULL);
xlSheetWriteNum(sheet, 3, 1, 1000, NULL);
}
xlBookSave(book, L"example.xls");
xlBookRelease(book);
}
return 0;
}





Thanks,

Faez
Previous Topic:Index - declared functions
Next Topic:Can't debug on Eclipse C/C++ on Windows
Goto Forum:
  


Current Time: Mon Dec 22 10:07:43 GMT 2014

Powered by FUDForum. Page generated in 0.02705 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software