000
17.03.2005, 22:03 Uhr
~Solour
Gast
|
hi,
ich hab da ein linker problem..:/
Code: |
D:\ListC>g++ -o main.exe main.o main.o(.text+0x603):main.cpp: undefined reference to `Element::maxLength' main.o(.text+0x613):main.cpp: undefined reference to `Element::maxLength' main.o(.text+0x626):main.cpp: undefined reference to `Element::maxLength' main.o(.text+0x670):main.cpp: undefined reference to `Element::maxLength' main.o(.text+0x6fa):main.cpp: undefined reference to `Element::maxLength' main.o(.text+0x74d):main.cpp: more undefined references to `Element::maxLength' follow collect2: ld returned 1 exit status
|
beim compilieren gibt es keine besonderen warnungen o.ä. ich benutze die aktuelle MinGW-Version hab schon gegoogled und bei anderen problemen mit selben fehler war es wie ich vermute compiler/OS abhängig ob der code verlinkt werden konnte allgemeine tipps zum code nehm ich aber auch gern an
der code: main.cpp
Code: |
#include <stdio.h> #include "log.cpp" #include "list.cpp"
#define MAIN_VERSION 0 #define APP_TITLE "ListTest"
int main(int argc, char* argv[]){ cout << APP_TITLE"\n"; Log logObj("logFile.txt", "errFile.txt"); logObj.pLn("test1"); logObj.logLn("test2"); logObj.logLn("test3"); logObj.logLn("test4"); List xl; Element elem("value1"); xl.pushFront(&elem); cout << (*(xl.popBack())).getValue(); //block until user types something fgetc(stdin); return 0; }
|
element.cpp
Code: |
#include <string.h>
class Element{ private: Element *next; Element *prev; char value[]; static int maxLength; public: Element(); Element(char value[]); void setPrev(Element *p); Element* getPrev(); void setNext(Element *n); Element* getNext(); void setValue(char val[]); char* getValue(); int compareTo(char value2[]); static void swapElems(Element *e1, Element *e2); };
Element::Element(){ maxLength= 255; }
Element::Element(char value[]){ maxLength= 255; setValue(value); setNext(NULL); setPrev(NULL); }
void Element::setPrev(Element *p){ prev= p; }
Element* Element::getPrev(){ return prev; }
void Element::setNext(Element *n){ next= n; }
Element* Element::getNext(){ return next; }
void Element::setValue(char val[]){ if(strlen(value)>maxLength) strcpy(value, ""); else strcpy(value, value); }
char* Element::getValue(){ return value; }
int Element::compareTo(char value2[]) { return strcmp(value,value2); }
void Element::swapElems(Element *e1, Element *e2){ char tmp[maxLength]; strcpy(tmp, (*e1).getValue()); (*e1).setValue((*e2).getValue()); (*e2).setValue(tmp); }
|
list.cpp
Code: |
#include <iostream.h> #include <fstream.h> #include "element.cpp"
class List{ private: Element *first; Element *last; int size; public: List(); ~List(); void pushFront(Element *elem); void pushBack(Element *elem); Element* popFront(); Element* popBack(); //Element topFront(); //Element topBack(); //void addList(List *list); //void addArray(Element *elems[]); //void quickSort(); //void cls(); //char* toString(); //bool isEmpty(); //int getSize(); //bool equal(); };
// constructor List::List(){ first= NULL; last= NULL; size= 0; }
// destructor List::~List(){ first= NULL; last= NULL; size= 0; }
void List::pushFront(Element *elem){ if(first==NULL){ first= elem; last= elem; (*elem).setNext(NULL); (*elem).setPrev(NULL); return; } (*elem).setNext(first); (*first).setPrev(elem); (*elem).setPrev(NULL); first= elem; size++; }
void List::pushBack(Element *elem){ if(first==NULL){ first= elem; last= elem; (*elem).setNext(NULL); (*elem).setPrev(NULL); return; } (*first).setNext(elem); (*elem).setPrev(first); (*elem).setNext(NULL); last= elem; size++; }
Element* List::popFront(){ if(size==0) return NULL; Element *result= first; if(size==1){ first= NULL; last= NULL; }else{ first= (*first).getNext(); (*first).setPrev(NULL); } (*result).setNext(NULL); (*result).setPrev(NULL); return result; }
Element* List::popBack(){ if(size==0) return NULL; Element *result= last; if(size==1){ first= NULL; last= NULL; }else{ last= (*last).getPrev(); (*last).setNext(NULL); } (*result).setNext(NULL); (*result).setPrev(NULL); return result; }
|
log.cpp
Code: |
#include <iostream.h> #include <fstream.h>
class Log{ private: char logFile[255]; char errFile[255]; public: Log(char* logFile, char* errFile); ~Log(); char* getLogFile(); char* getErrFile(); void setLogFile(char logF[]); void setErrFile(char errF[]); void p(char msg[]); void pLn(char msg[]); void log(char msg[]); void logLn(char msg[]); void err(char msg[]); void errLn(char msg[]); };
// constructor Log::Log(char logF[255], char errF[255]){ setLogFile(logF); setErrFile(errF); }
// destructor Log::~Log(){ // empty destructor }
// getter methods char* Log::getLogFile(){ return logFile; }
char* Log::getErrFile(){ return errFile; }
// setter methods void Log::setLogFile(char logF[]){ strcpy(logFile, logF); }
void Log::setErrFile(char errF[]){ strcpy(errFile, errF); }
// console output, no logging void Log::p(char msg[]){ cout << msg; }
void Log::pLn(char msg[]){ char tmp[strlen(msg)+2]; strcpy(tmp, msg); p(strcat(tmp, "\n")); }
// no console output, logging only to logFile void Log::log(char msg[]){ fstream file_op(logFile, ios::out|ios::app); if(file_op.is_open()){ file_op << msg; file_op.close(); }else errLn("[Log][Error] : Could not open logFile."); }
void Log::logLn(char msg[]){ char tmp[strlen(msg)+2]; strcpy(tmp, msg); log(strcat(tmp, "\n")); }
// no console output, logging only to errFile void Log::err(char msg[]){ fstream file_op(errFile, ios::out|ios::app); if(file_op.is_open()){ file_op << msg; file_op.close(); }else cout << "[Log][Error] : Could not open errFile."; }
void Log::errLn(char msg[]){ char tmp[strlen(msg)+2]; strcpy(tmp, msg); err(strcat(tmp, "\n")); }
|
gratz |