Mal wieder ein Compilerfehler, den ich nicht verstehe...



  • Habe folgenden Code geschrieben (noch nicht fertig):

    #ifndef DATABUFFER_H
    #define DATABUFFER_H
    
    #include <string>
    #include <vector>
    #include <iostream>
    #include <sstream>
    #include <fstream>
    
    #include <time.h>
    #include <stdio.h>
    
    #include "Constants.h"
    
    class Data {
    	public:
    	static const int bufferSize = 22*sizeof(int)+3*sizeof(double)+100*sizeof(char);
    	char buffer[bufferSize];
    
    	int autolartVector[Constants::numberOfPoissonAttributes + Constants::numberOfASNAttributes];
    	double llrPoisson;
    	double llrMulti;
    	double llr;
    	std::string domain;
    };
    
    class DataBuffer {
    	public:
    
    	void convertData( std::string filename );
    	std::vector<Data> convertBinaryDataToText( char* data, int dataLength, std::string filename );
    	void writeTextDataToFile( std::vector<Data>& data, std::string filename );
    	char* readDataFromFile( std::string filename );
    
    };
    
    #endif
    
    #include "DataBuffer.h"
    
    using namespace std;
    
    void DataBuffer::convertData( std::string filename ) {
    	readDataFromFile( filename );
    }
    
    std::vector<Data> DataBuffer::convertBinaryDataToText( char* binData, int dataLength, std::string filename ) {
    
    	std::vector<Data> data;
    	char* bufferPointer;
    
    	for( int i = 0; i < dataLength; ++i ) {
    		Data d;
    		memcpy( d.autolartVector, bufferPointer, sizeof(int)*(Constants::numberOfPoissonAttributes + Constants::numberOfASNAttributes) );
    		bufferPointer += sizeof(int)*(Constants::numberOfPoissonAttributes + Constants::numberOfASNAttributes);
    
    		memcpy( &d.llrPoisson, bufferPointer, sizeof( double ) );
    		bufferPointer += sizeof(double);
    		memcpy( &d.llrMulti, bufferPointer, sizeof( double ) );
    		bufferPointer += sizeof(double);
    		memcpy( &d.llr, bufferPointer, sizeof( double ) );
    		bufferPointer += sizeof(double);
    
    		char domainName[100];
    		strncpy( domainName, bufferPointer, 100 );
    		domainName[99] = '\0';
    		d.domain = string(domainName);
    
    		data.push_back(d);
    	}
    
    	return data;
    
    }
    
    void DataBuffer::writeTextDataToFile( std::vector<Data>& data, std::string filename ) {
    	ofstream file( filename.c_str() );
    	for( size_t i = 0; i < data.size(); ++i ) {
    		stringstream ss;
    		ss << data[i].domain << "\t" << data[i].llrPoisson << "\t" << data[i].llrMulti << "\t" << (data[i].llrPoisson+data[i].llrMulti) << "\t";
    		for( int j = 0; j < Constants::numberOfPoissonAttributes + Constants::numberOfASNAttributes; ++j )
    			ss << data[i].autolartVector[i];
    		ss << endl;
    		file << ss.str();
    	}
    	file.close();
    }
    
    char* readDataFromFile( std::string filename ) {
    	FILE* infile = NULL;
    
    	infile = fopen( filename.c_str(), "rb" );
    	fseek( infile, 0, SEEK_END );
    	int fileSize = ftell( infile );
    	// return the file pointer to begin of file if you want to read it
    	rewind( infile );
    
    	cout << "Dateigroesse = " << fileSize << " bytes" << endl;
    
    	fclose( infile );
    
    	return 0;
    }
    

    Und bekomme diese endlos langen Fehler beim Linken:

    make
    g++ -m64 -g -Wall -Werror -Wcomment -o DataBuffer.o -c DataBuffer.cpp
    gcc -m64 -Wall -Werror -Wcomment -o Converter Converter.o DataBuffer.o
    Converter.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()'
    Converter.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()'
    Converter.o: In function main': /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference tostd::allocator<char>::allocator()'
    /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference to std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference tostd::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
    /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference to std::basic\_string<char, std::char\_traits<char>, std::allocator<char> >::~basic_string()' /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference tostd::allocator<char>::~allocator()'
    /mnt/raid0/7k2/uniuser/ddos/autolart/traffic/ConvertBinaryTraffic2Text/Converter.cpp:7: undefined reference to std::allocator<char>::~allocator()' Converter.o:(.eh\_frame+0x13): undefined reference to__gxx_personality_v0'
    DataBuffer.o: In function `__static_initialization_and_destruction_0':
    usw...

    Was ist falsch? Ich sehe es nicht...



  • sollte ich noch nachliefern:
    Converter.cpp

    #include <iostream>
    
    #include "DataBuffer.h"
    
    int main() {
    	DataBuffer db;
    	db.convertData("../trafficFiles/traffic_1290728731");
    	return 0;
    }
    

  • Mod

    Du benutzt einen C Compiler



  • Undefined references to internal run-time library functions, such as __gxx_personality_v0, are also a symptom of linking C++ object files with gcc instead of g++. Linking the same object file with g++ supplies all the necessary C++ libraries and will produce a working executable

    http://www.network-theory.co.uk/docs/gccintro/gccintro_54.html



  • An deiner Stelle würd ich <fstream> für Dateioperationen benutzen. Damit ersparst du dir z. B. Ärger bei Exceptions oder kannst direkt in nen std::string einlesen.



  • Danke!



  • Meinst Du sowas hier?

    ofstream outfile(filename, ios::out | ios::binary );
    outfile << "blabla";
    outfile.close();
    ...
    ifstream infile(filename, ios::in | ios::binary );
    string name;
    infile >> name;
    infile.close();
    

  • Mod

    HändyÄndy schrieb:

    Meinst Du sowas hier?

    ofstream outfile(filename, ios::out | ios::binary );
    outfile << "blabla";
    outfile.close();
    ...
    ifstream infile(filename, ios::in | ios::binary );
    string name;
    infile >> name;
    infile.close();
    

    Ja, er meint so etwas in der Art. Aber sicherlich ohne close() und mit besserem Verständnis für die Modi und Operatoren.



  • dazu die leider viel zu üblichen Fehler:
    <time.h> und <stdio.h> sind kein C++. Dort heißen sie <ctime> und <cstdio> und ihre Inhalte liegen im Namespace std.

    Außerdem slltest du std::strings besser als const referenzen übergeben statt sie zu kopieren. Und wenn du sie schon benutzt kannst du das auch dort tun wo du noch strncpy und ähnliches benutzt.



  • Tja, programmier normalerweise kein C++. Deswegen hab ich auch nicht viel Ahnung davon...



  • HändyÄndy schrieb:

    Tja, programmier normalerweise kein C++. Deswegen hab ich auch nicht viel Ahnung davon...

    Um ehrlich zu sein sieht man das. Du solltest dir auf jeden Fall mal ein paar der Grundlagen anschauen bevor du da weiter herumprobierst. Leider funktioniert das anders nicht wirklich.


Anmelden zum Antworten