Hackerboard Wiki HaboBlog
Hackerboard bei Facebook Hackerboard bei Google+ Hackerboard bei Twitter

[HaBo]

 
Code Kitchen Allgemeines Coder-Forum rund um das Programmieren eigenständiger, ausführbarer Programme.

g++ Linker Error: undefined reference to

Diskussion: g++ Linker Error: undefined reference to im Forum Code Kitchen, in der Kategorie Software Home; Anzeige Hallo! Ich kriege folgende Fehlermeldung beim Linken eines Testprogramms, welches eine Testklasse nutzt. Code: # g++ -o FooMain FooMain.cpp ...

Antwort
Alt 03.02.08, 13:52   #1 (permalink)
 
Benutzerbild von Plexo
 
Registriert seit: 18.09.05
Plexo Leistung: Facit NTK
Likes: 0
Standard g++ Linker Error: undefined reference to

Anzeige

Hallo!

Ich kriege folgende Fehlermeldung beim Linken eines Testprogramms, welches eine Testklasse nutzt.

Code:
# g++ -o FooMain FooMain.cpp
/tmp/ccSYd552.o: In function `main':
FooMain.cpp:(.text+0x8b): undefined reference to `Foo::Foo()'
FooMain.cpp:(.text+0x96): undefined reference to `Foo::get()'
FooMain.cpp:(.text+0xc9): undefined reference to `Foo::set(int)'
FooMain.cpp:(.text+0xd4): undefined reference to `Foo::get()'
FooMain.cpp:(.text+0x104): undefined reference to `Foo::~Foo()'
FooMain.cpp:(.text+0x11a): undefined reference to `Foo::~Foo()'
collect2: ld gab 1 als Ende-Status zurück
Und hier sind noch die Quellcodes.

Code:
// FooMain.cpp
#include <iostream>

using namespace std;

#include "Foo.hpp"

int main()
{
	Foo f;
	
	cout << f.get() << endl;
	
	f.set( 5 );
	
	cout << f.get() << endl;
	
	return 0;
}
Code:
// Foo.hpp
class Foo
{
	private:
		int foo;
	
	public:
		Foo();
		~Foo();
		
		void set( int );
		int get();
};
Code:
// Foo.cpp
#include "Foo.hpp"

Foo::Foo()
{
	foo = 1;
}

Foo::~Foo()
{

}

int Foo::get()
{
	return foo;
}

void Foo::set( int i )
{
	foo = i;
}
Ich hoffe, dass mir jemand helfen kann.

Danke schonmal!

Gruß
Plexo ist offline   Mit Zitat antworten
Alt 03.02.08, 14:13   #2 (permalink)
 
Benutzerbild von Avenger
 
Registriert seit: 27.12.03
Avenger Leistung: Facit NTK
Avenger eine Nachricht über ICQ schicken
Likes: 0
Standard

Welche IDE benutzt du?
Avenger ist offline   Mit Zitat antworten
   
HaBOT
 
- Anzeige -

Werbung ist gerade online    
Alt 03.02.08, 14:20   #3 (permalink)
Themenstarter
 
Benutzerbild von Plexo
 
Registriert seit: 18.09.05
Plexo Leistung: Facit NTK
Likes: 0
Standard

Zitat:
Original von Avenger
Welche IDE benutzt du?
Keine!
Plexo ist offline   Mit Zitat antworten
Alt 03.02.08, 14:28   #4 (permalink)
 
Registriert seit: 05.10.05
Inliferty Leistung: 8086
Inliferty eine Nachricht über ICQ schicken
Likes: 5
Standard

Sieht mir eher nach einem Linker-Problem aus.
Nachdem du keine IDE verwendest, könntest du bitte posten mit welchem Commands du die Source-Datein kompilierst und linkst?

*argh*
Gerade gesehen das es eh in der 1 Code-Zeile steht.
Naja irgendwie fehlt als Input-File die Foo.cpp

Mfg Iarumas
Inliferty ist offline   Mit Zitat antworten
Alt 03.02.08, 14:37   #5 (permalink)
Themenstarter
 
Benutzerbild von Plexo
 
Registriert seit: 18.09.05
Plexo Leistung: Facit NTK
Likes: 0
Standard

Zitat:
Original von Iarumas
Sieht mir eher nach einem Linker-Problem aus.
Nachdem du keine IDE verwendest, könntest du bitte posten mit welchem Commands du die Source-Datein kompilierst und linkst?

*argh*
Gerade gesehen das es eh in der 1 Code-Zeile steht.
Naja irgendwie fehlt als Input-File die Foo.cpp

Mfg Iarumas
Hab das Kommando in das folgende geändert und es klappt. Danke!

Code:
g++ -o FooMain Foo.cpp FooMain.cpp
Plexo ist offline   Mit Zitat antworten
Alt 03.02.08, 14:38   #6 (permalink)
 
Registriert seit: 17.02.06
Harry Boeck Leistung: Facit NTK
Likes: 0
Standard

Dann solltest Du dem Linker sagen, daß zu Deinem Programm neben der "FooMain.obj" auch die "Foo.obj" zu linken ist!

Für Schnellhilfe poste mal die Kommandozeile für das Erstellen Deines Programms!
Harry Boeck ist offline   Mit Zitat antworten
Alt 03.02.08, 15:02   #7 (permalink)
Themenstarter
 
Benutzerbild von Plexo
 
Registriert seit: 18.09.05
Plexo Leistung: Facit NTK
Likes: 0
Standard

Kann geschlossen werden!

Und Danke nochmal!

Gruß
Plexo ist offline   Mit Zitat antworten
Antwort
   
- Anzeige -

Werbung ist gerade online    

[HaBo] » Software Home » Code Kitchen » g++ Linker Error: undefined reference to
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind aus
Pingbacks sind aus
Refbacks sind aus


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Qt: undefined reference to `vtable for rami Code Kitchen 2 18.03.09 21:29
undefined reference to `vtable for filereadingfind' [C++][geloest] sw33tlull4by Code Kitchen 2 07.02.09 19:36
DS Linker gaga Games 5 11.10.08 22:36
linker Halpha Code Kitchen 8 24.08.06 17:23
gcc: undefined reference to 'WSAStartup@8' 2Bios Code Kitchen 2 09.09.05 15:46


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61