undefined reference to...



  • Hallo!
    Ich habe hier ein kurzes Beispiel für mein Problem geschrieben, dass mir die Fehlermeldung
    b.o(.text+0x23): In function `main':
    undefined reference to 'a::test()'
    liefert: 😕

    class a{
    	public:
    	static int test();
    };
    
    #include "a.h"
    
    int test(){
    	return 42;
    }
    
    #include <iostream>
    using namespace std;
    
    class b{
    	public:
    	int b1;	
    };
    
    #include "b.h"
    #include "a.h"
    
    int main(){
    	cout << a::test();   
    	return 1;
    }
    

    Was ist hier falsch???

    Ach so, hier noch das makefile:

    all: a.o b.o 
    	g++ -o test.exe a.o b.o
    
    clean:
    	rm *.o
    
    a.o: a.h a.cpp
    	g++ -g -Wall -c a.cpp
    
    b.o: b.h b.cpp
    	g++ -g -Wall -c b.cpp
    

    Vielen Dank für Ihre Unterstützung. 😃 🕶



  • raphael2 schrieb:

    #include "a.h"
    
    int test(){
    	return 42;
    }
    

    Was ist hier falsch???

    Es muss:
    [cpp]
    int **a::**test() {
    return 42;
    }
    [/cpp]
    heißen. Schließlich willst du ein Member von a definieren, keine globale Funktion.



  • vielen Dank, habe den Fehler... 🙂


Anmelden zum Antworten