Anzeige:
Ergebnis 1 bis 7 von 7

Thema: Probleme bei der Codetrennung unter Linux

  1. #1
    Registrierter Benutzer
    Registriert seit
    20.11.2006
    Beiträge
    13

    Probleme bei der Codetrennung unter Linux

    Hi,

    Hab eine wichtige Frage bei der ich nicht weiterkomme. Ich habe mit C++ eine Klasse geschrieben und sie schön und Header und Definitionsdatei aufgeteilt. Nun binde ich die Header in die Code datei ein die das mainProgramm enthält. Sobald ich nun compilieren will erhalte ich eine Fehlermeldung und zwar:
    Code:
    OGLWidget.o: In function `SWP0607::OGLWidget::drawBall(SWP0607::MyVector3Df)':
    /home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::z()'
    /home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::y()'
    /home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::x()'
    collect2: ld returned 1 exit status
    make: *** [Softwarepraktikum] Fehler 1
    Hier ist meine Headerdatei:
    Code:
    #ifndef _MY_VECTOR3DF_HH_
    #define _MY_VECTOR3DF_HH_
    
    namespace SWP0607 {
    
    class MyVector3Df
    {
    private:
    	float m_x, m_y, m_z;	// Vektorkomponenten
    public:
    	// Konsturktor(en)
    	MyVector3Df();
    	MyVector3Df(const MyVector3Df & v);
    	MyVector3Df(const float, const float, const float);
    
    	// Zugriffsmethoden
    
    	inline float 	x();
    	inline float 	y();
    	inline float 	z();
    	inline void	setX(float);
    	inline void	setY(float);
    	inline void	setZ(float);
    
    
    	// Operatoren
    
    	// arithmetische Operatoren
    	inline MyVector3Df operator + (const MyVector3Df & v); // Komponentenweise
    	inline MyVector3Df operator - (const MyVector3Df & v); // Komponentenweise
    	inline MyVector3Df operator * (const MyVector3Df & v); // Komponentenweise
    	inline MyVector3Df operator / (const MyVector3Df & v); // Komponentenweise
    	inline MyVector3Df operator * (const float f);	  // Skalarmultiplikation
    	friend MyVector3Df operator * (const float f, const MyVector3Df & v);
    	inline MyVector3Df operator / (const float f);	  // Skalardivision
    
    	// Zuweisungsoperatoren
    	MyVector3Df& operator  = (const MyVector3Df & v);
    	MyVector3Df& operator += (const MyVector3Df & v);
    	MyVector3Df& operator -= (const MyVector3Df & v);
    	MyVector3Df& operator *= (const MyVector3Df & v);
    	MyVector3Df& operator /= (const MyVector3Df & v);
    	
    	// Vergleichsoperatoren
    	bool operator == (const MyVector3Df & v);
    	bool operator != (const MyVector3Df & v);
    
    
    	// Methoden
    	inline float length();		// liefert Vektorlänge
    	inline float lengthSq();	// liefert Vektorlänge²
    
    
    };	
    	inline MyVector3Df operator * (const float f, const MyVector3Df & v);
    }
    
    #endif
    Und hier die cc Datei
    Code:
    #include "myvector3df.hh"
    #include <math.h>
    
    namespace SWP0607 {
    
    MyVector3Df::MyVector3Df()
    {
    }
    
    MyVector3Df::MyVector3Df(const MyVector3Df & v) : m_x(v.m_x), m_y(v.m_y), m_z(v.m_z)
    {
    }
    
    MyVector3Df::MyVector3Df(const float x, 
    			 const float y, 
    			 const float z) : m_x(x), m_y(y), m_z(z)
    {
    }
    
    float MyVector3Df::x()
    {
    	return m_x;
    }
    
    float MyVector3Df::y()
    {
    	return m_y;
    }
    
    float MyVector3Df::z()
    {
    	return m_z;
    }
    
    void  MyVector3Df::setX(float nX)
    {
    	m_x = nX;
    }
    
    void  MyVector3Df::setY(float nY)
    {
    	m_y = nY;
    }
    
    void  MyVector3Df::setZ(float nZ)
    {
    	m_z = nZ;
    }
    
    MyVector3Df MyVector3Df::operator + (const MyVector3Df & v)
    {
    	return MyVector3Df(m_x + v.m_x,
    			    m_y + v.m_y,
    			    m_z + v.m_z);
    }
    
    MyVector3Df MyVector3Df::operator - (const MyVector3Df & v)
    {
    	return MyVector3Df(m_x - v.m_x,
    			    m_y - v.m_y,
    			    m_z - v.m_z);
    }
    
    MyVector3Df MyVector3Df::operator * (const MyVector3Df & v)
    {
    	return MyVector3Df(m_x * v.m_x,
    			    m_y * v.m_y,
    			    m_z * v.m_z);
    }
    
    MyVector3Df MyVector3Df::operator / (const MyVector3Df & v)
    {
    	return MyVector3Df(m_x / v.m_x,
    			    m_y / v.m_y,
    			    m_z / v.m_z);
    }
    
    MyVector3Df MyVector3Df::operator * (const float f)
    {
    	return MyVector3Df(m_x * f,
    			    m_y * f,
    			    m_z * f);
    }
    
    MyVector3Df operator * (const float f, const MyVector3Df & v)
    {
    	return MyVector3Df(v.m_x * f,
    			    v.m_y * f,
    			    v.m_z * f);
    }
    
    MyVector3Df MyVector3Df::operator / (const float f)
    {
    	return MyVector3Df(m_x / f,
    			    m_y / f,
    			    m_z / f);
    }
    
    MyVector3Df& MyVector3Df::operator  = (const MyVector3Df & v)
    {
    	m_x = v.m_x;
    	m_y = v.m_y;
    	m_z = v.m_z;
    
    	return *this;
    }
    
    MyVector3Df& MyVector3Df::operator += (const MyVector3Df & v)
    {
    	m_x += v.m_x;
    	m_y += v.m_y;
    	m_z += v.m_z;
    
    	return *this;
    }
    
    MyVector3Df& MyVector3Df::operator -= (const MyVector3Df & v)
    {
    	m_x -= v.m_x;
    	m_y -= v.m_y;
    	m_z -= v.m_z;
    
    	return *this;
    }
    
    MyVector3Df& MyVector3Df::operator *= (const MyVector3Df & v)
    {
    	m_x *= v.m_x;
    	m_y *= v.m_y;
    	m_z *= v.m_z;
    
    	return *this;
    }
    
    MyVector3Df& MyVector3Df::operator /= (const MyVector3Df & v)
    {
    	m_x /= v.m_x;
    	m_y /= v.m_y;
    	m_z /= v.m_z;
    
    	return *this;
    }
    
    bool MyVector3Df::operator == (const MyVector3Df & v)
    {
    	return (m_x == v.m_x) && (m_y == v.m_y) && (m_y == v.m_z);
    }
    
    bool MyVector3Df::operator != (const MyVector3Df & v)
    {
    	return (m_x != v.m_x) || (m_y != v.m_y) || (m_y != v.m_z);
    }
    
    float MyVector3Df::length()
    {
    	return sqrtf(m_x*m_x + m_y*m_y + m_z*m_z);	
    }
    	
    float MyVector3Df::lengthSq()
    {
    	return m_x*m_x + m_y*m_y + m_z*m_z;
    }
    
    }
    Die Fehlermeldung die ich da erhalte bezieht sich auf die Zugriffsmethoden weil ich nur die in der Hauptdatei benutzt habe. Aber sobald ich eine andere Methode benutze wird auch gemeckert.
    Muss ich vielleicht etwas in der Makefile dazuschreiben?

  2. #2
    Registrierter Benutzer
    Registriert seit
    20.11.2006
    Beiträge
    13
    Jetzt habe ich nochmal zum testen ein ganz simples main Programm aufgesetzt:
    Code:
    #include <stdio.h>
    #include "myvector3df.hh"
    
    using namespace SWP0607;
    
    int main()
    {
    	MyVector3Df test();
    	test.length();
    	return 0;
    }
    Wenn ich das kompilieren will erhalte ich folgende Meldung:
    Code:
    main.cc: In function ‘int main()’:
    main.cc:9: error: request for member ‘length’ in ‘test’, which is of non-class type ‘SWP0607::MyVector3Df ()()’
    make: *** [main.o] Fehler 1

  3. #3
    Registrierter Benutzer Avatar von peschmae
    Registriert seit
    14.03.2002
    Ort
    Schweizland
    Beiträge
    4.549
    Ich krieg auch die gleiche Fehlermeldung - sehe wirklich nicht wo die herkommt. Wenn ich das Ding auf den Heap anlege gehts

    MfG Peschmä
    The greatest trick the Devil ever pulled was convincing the world he didn't exist. -- The Usual Suspects (1995)
    Hey, I feel their pain. It's irritating as hell when people act like they have rights. The great old one (2006)

  4. #4
    Registrierter Benutzer
    Registriert seit
    20.11.2006
    Beiträge
    13
    Ich hab jetzt einfach mal die ganzen inlines vor den Methoden weggemacht und dann läuft es super

  5. #5
    Registrierter Benutzer Avatar von peschmae
    Registriert seit
    14.03.2002
    Ort
    Schweizland
    Beiträge
    4.549
    Achso, genau. Ich glaube bei Inline solltest du auch gleich die Funktionsdefinition mit ins Header nehmen - sonst kann der Compiler ja gar nicht inlinen, wenn du in main.cpp das Header includest, weil er da ja gar nicht weiss, wie die Funktion genau aussieht. Ist aber schon ne Weile her dass ich das benutzt habe - bitte korrigieren wenn ich Blödsinn erzähle

    MfG Peschmä
    The greatest trick the Devil ever pulled was convincing the world he didn't exist. -- The Usual Suspects (1995)
    Hey, I feel their pain. It's irritating as hell when people act like they have rights. The great old one (2006)

  6. #6
    Registrierter Benutzer
    Registriert seit
    18.03.2005
    Beiträge
    211
    sonst kann der Compiler ja gar nicht inlinen, wenn du in main.cpp das Header includest
    komischer weisse geht das bei dem MS Zeugs ... ^^
    nen normaler compiler sollt damit eigentlich nicht ins straucheln kommen, er muesst versuchen ob er den code findet (in der cpp datei) nen binaerblock generieren und an der stelle wo es verwendet wird einfuegen.
    Was aber ned geht wenn man die cpp's seperat uebersetzt ^^
    dann sollt er aber das inline komplett ignorieren ...

    Um welchen compiler in welcher version handelt es sich hier ?

    Ciao ...

  7. #7
    Registrierter Benutzer Avatar von peschmae
    Registriert seit
    14.03.2002
    Ort
    Schweizland
    Beiträge
    4.549
    g++ 4.1.2 bei mir. Wobei ich das im konkreten Fall nicht mal separat kompiliert habe (zumindest die Anweisung war für in einem Schnauf - was er dann damit macht weiss ich nicht )

    MfG Peschmä
    The greatest trick the Devil ever pulled was convincing the world he didn't exist. -- The Usual Suspects (1995)
    Hey, I feel their pain. It's irritating as hell when people act like they have rights. The great old one (2006)

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •