Ich sehe nicht den Fehler...



  • Habe folgendes geschrieben

    Sorter.cpp

    #include <string>
    #include <vector>
    #include <fstream>
    #include <iostream>
    #include <sstream>
    
    using namespace std;
    
    class webpage {
    
    	public:
    	std::string url;
    	int count;
    	webpage( std::string url, int count );
    
    };
    
    webpage::webpage( string url_, int count_ ) {
    	url = url_;
    	count = count_;
    }
    
    int main() {
    	return 0;
    }
    

    So sieht mein makefile aus:

    CFLAGS = -m64 -g -Wall -Werror -Wcomment
    LDFLAGS = -m64 -Wall -Werror -Wcomment

    all: Sorter

    Sorter.o : Sorter.cpp Sorter.h
    g++ ${CFLAGS} -o Sorter.o -c Sorter.cpp

    Sorter: Sorter.o
    gcc ${LDFLAGS} -o Sorter Sorter.o

    clean:
    rm -f *.o
    rm -f Sorter

    und ich erhalte folgende Fehlermeldung:

    make
    g++ -m64 -g -Wall -Werror -Wcomment -o Sorter.o -c Sorter.cpp
    gcc -m64 -Wall -o Sorter Sorter.o
    Sorter.o: In function \_\_static\_initialization\_and\_destruction_0': /usr/lib/gcc/x86\_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iostream:76: undefined reference tostd::ios_base::Init::Init()'
    Sorter.o: In function \_\_tcf\_0': /usr/lib/gcc/x86\_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iostream:76: undefined reference tostd::ios_base::Init::~Init()'
    Sorter.o: In function webpage': /mnt/raid0/7k2/uniuser/ddos/autolart/output\_files/Sorter.cpp:18: undefined reference tostd::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
    /mnt/raid0/7k2/uniuser/ddos/autolart/output_files/Sorter.cpp:19: undefined reference to std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >::operator=(std::basic\_string<char, std::char_traits<char>, std::allocator<char> > const&)' /mnt/raid0/7k2/uniuser/ddos/autolart/output\_files/Sorter.cpp:21: undefined reference tostd::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    /mnt/raid0/7k2/uniuser/ddos/autolart/output_files/Sorter.cpp:18: undefined reference to std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >::basic\_string()' /mnt/raid0/7k2/uniuser/ddos/autolart/output\_files/Sorter.cpp:19: undefined reference tostd::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /mnt/raid0/7k2/uniuser/ddos/autolart/output_files/Sorter.cpp:21: undefined reference to std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >::~basic\_string()' Sorter.o:(.eh\_frame+0x13): undefined reference to__gxx_personality_v0'
    collect2: ld returned 1 exit status
    make: *** [Sorter] Error 1

    Was geht hier ab? Ich verstehe den Compiler nicht.



  • Du bindest ohne C++-Standardbibliothek. Verwende im Makefile zum Binden g++ statt gcc.



  • HändyÄndy schrieb:

    gcc ${LDFLAGS} -o Sorter Sorter.o

    Mein gcc-fu ist etwas eingerostet, aber müsste dort nicht g++ statt gcc stehen?



  • Habe gcc durch g++ ersetzt, jetzt gehts. Danke!


Anmelden zum Antworten