Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

06.01.2008, 12:57

Mehrfachdefinitionen in der Logfile

Hallo ich habe die Logfile direkt aus dem Buch abgetippt und versucht sie zu kompilieren doch dann hat sich der Compiler über eine Mehrfachdefinition aller Logfileklassenmemberfunktionen beschwert.Hoffe mir kann jemand helfen.
Hier kommt mal der Code(Falls es hilft ich benutze Dev-Cpp):

Logfile.hpp:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _CLOGFILE
#define _CLOGFILE

#include <stdio.h>
#include <windows.h>
#include <iostream>
#include "Singletons.hpp"
using namespace std;
#define MAX_BUFFER 1024
#define L_FAIL false
#define L_OK true
#define g_pLogfile CLogfile::get()

enum FONTCOLORS
{
     BLACK,RED,GREEN,BLUE,PURPLE
     };

class CLogfile : public TSingleton<CLogfile>
{
  public:
         CLogfile           ();
         ~CLogfile          ();
  void   CreateLogfile      (const char *);
  void   WriteTopic         (const char *,int);
  void   Textout            (const char*);
  void   Textout            (int,const char*);
  void   Textout            (int,bool,const char*);
  void  fTextout            (const char*,...);
  void  fTextout            (int,const char*,...);
  void  fTextout            (int,bool, const char*,...);
  void  FunctionResult      (const char*,bool);
  
  private:
        
     FILE *m_Logfile;
     };
#endif


Logfile.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "Logfile.hpp"
using namespace std;
CLogfile::CLogfile()
{
 }
 
CLogfile::~CLogfile()
{
 Textout("<br><br>End of Logfile</font></body></html>");
 fclose(m_Logfile);                    
 }   
 
void CLogfile::CreateLogfile(const char* LogName)
{
  m_Logfile=fopen(LogName,"w");
  
  Textout("<html><head><title>Logfile</title></head>");
  Textout("<body><font face='courier new'>");
  WriteTopic("Logfile",3);
  #ifdef _DEBUG
    Textout("BUILD:DEBUG<br>");
  #else
    Textout("BUILD:RELEASE<br>");
  #endif
  
  fclose(m_Logfile);
  m_Logfile = fopen(LogName,"a");
}

  
void CLogfile::WriteTopic(const char* Topic,int Size)
{
    Textout("<table cellspacing ='0' cellpadding='0' width='100%%'");
    Textout("bgcolor='DFDFE5'>\n<tr>\n<td>\n<font face='arial'");
    fTextout("size='+%i'>\n",Size);
    Textout(Topic);
    Textout("</font>\n</td>\n</tr>\n</table>\n<br>");
    fflush(m_Logfile);
}


void CLogfile::Textout (const char *Text)
{
  fprintf(m_Logfile,Text);
  fflush(m_Logfile);
 }
 
void CLogfile::Textout (int Color,const char* Text)
{
   Textout(Color,false,Text);
}


void CLogfile::Textout(int Color,bool List,const char*Text)
{
   if(List==true)
   Textout("<li>");
   
   switch (Color)
   {
    case BLACK:
     Textout("<font color=black>"); break;
    case RED:                   
     Textout("<font color=red>"); break;
    case GREEN:      
     Textout("<font color=green>"); break;
    case BLUE:                          
     Textout("<font color=blue>"); break;
    case PURPLE:
     Textout("<font color=purple>");break;
     };
    Textout(Text);
    Textout("</font>");
    if(List==false)
      Textout("<br>");
    else
      Textout("</li>");
      }
                                                                          
void CLogfile::fTextout(const char*Text,...)
{
  TCHAR buffer[MAX_BUFFER];
  va_list pArgList;
  va_start(pArgList,Text);
  vsprintf(buffer,Text,pArgList); 
  va_end(pArgList);
  Textout(buffer);
}  
void CLogfile::fTextout(int Color,const char*Text,...)
{
    TCHAR buffer[MAX_BUFFER];
    va_list pArgList;
    va_start(pArgList,Text);
    vsprintf(buffer,Text,pArgList); 
    va_end(pArgList); 
    Textout(Color,buffer);
}

 
void CLogfile::fTextout(int Color,bool List,const char*Text,...)
{
    TCHAR buffer[MAX_BUFFER];
    va_list pArgList;
    va_start(pArgList,Text);
    vsprintf(buffer,Text,pArgList);
    va_end(pArgList); 
    Textout(Color,List,buffer);
}     
     
void CLogfile::FunctionResult(const char *Name,bool Result)
{
     if(L_OK == Result)
     {
       Textout("<table width='100%%' cellSpacing='1' cellPading='5'");
       Textout("border='0' bgcolor='#c0c0c0'><tr><td bgcolor=");
       fTextout("'#FFFFFF' width='35%%'>%s</TD>",Name);
       Textout("<td bgcolor='#FFFFFF' width='30%%'><font color=");           
       Textout("'green'>OK</FONT></TD><td bgcolor='#FFFFFF'");
       Textout("width='35%%'>-/-</TD></tr></table");
       }
       else
      {
       Textout("<table width='100%%' cellSpacing='1' cellPading='5'");
       Textout("border='0' bgcolor='#c0c0c0'><tr><td bgcolor=");
       fTextout("'#FFFFFF' width='35%%'>%s</TD>",Name);
       Textout("<td bgcolor='#FFFFFF' width='30%%'><font color=");           
       Textout("'red'>ERROR</FONT></TD><td bgcolor='#FFFFFF'");
       Textout("width='35%%'>-/-</TD></tr></table");
      }   
      
      }


Und die Main hab sie ein bischen gekürzt:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "Logfile.cpp"
#include <iostream>
using namespace std;

int main()
{
    float Kontrolle =123.456f;
    
    g_pLogfile->CreateLogfile("Logfile.html");
    g_pLogfile ->WriteTopic("Unformatierter Text",2);
    g_pLogfile ->Textout("Normaler schwarzer text<br>");
    g_pLogfile->Textout(RED,"Roter text");
    g_pLogfile->WriteTopic("Formatierter text",2);
    g_pLogfile->fTextout(RED,"Kontrollvariable: %f",Kontrolle);
    g_pLogfile->fTextout(GREEN,true,"Liste Kontrolle:%f",Kontrolle); 
    g_pLogfile->fTextout(GREEN,true,"Liste Kontrolle:%f",Kontrolle*2.0f);
    g_pLogfile->fTextout(GREEN,true,"Liste Kontrolle:%f",Kontrolle*4.0f);
    g_pLogfile->FunctionResult("Funktion 1",L_OK);
    g_pLogfile->FunctionResult("Funktion 2",L_FAIL);
    g_pLogfile->del();
    return 0;
}

und der Fehlercode:


Compiler: Default compiler
Building Makefile: "C:\Programme\Dev-Cpp\Projekte\Logfile\Makefile.win"
Führt make clean aus
rm -f Logfile.o main.o Logfile.exe

g++.exe -D__DEBUG__ -c Logfile.cpp -o Logfile.o -I"C:/Programme/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2" -I"C:/Programme/Dev-Cpp/include" -pg -g3

g++.exe -D__DEBUG__ -c main.cpp -o main.o -I"C:/Programme/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Programme/Dev-Cpp/include/c++/3.4.2" -I"C:/Programme/Dev-Cpp/include" -pg -g3

g++.exe -D__DEBUG__ Logfile.o main.o -o "Logfile.exe" -L"C:/Programme/Dev-Cpp/lib" -lgmon -pg -g3

main.o(.text+0x10a): In function `ZN8CLogfileC2Ev':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:4: multiple definition of `CLogfile::CLogfile()'
Logfile.o(.text+0x10a):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:4: first defined here
main.o(.text+0x130): In function `ZN8CLogfileC1Ev':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:4: multiple definition of `CLogfile::CLogfile()'
Logfile.o(.text+0x130):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:4: first defined here
main.o(.text+0x156): In function `ZN8CLogfileD2Ev':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: multiple definition of `CLogfile::~CLogfile()'
Logfile.o(.text+0x156):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: first defined here
main.o(.text+0x23e): In function `ZN8CLogfileD1Ev':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: multiple definition of `CLogfile::~CLogfile()'
Logfile.o(.text+0x23e):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: first defined here
main.o(.text+0x326): In function `ZN8CLogfileD0Ev':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: multiple definition of `CLogfile::~CLogfile()'
Logfile.o(.text+0x326):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:8: first defined here
main.o(.text+0x40e): In function `ZN8CLogfile13CreateLogfileEPKc':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:14: multiple definition of `CLogfile::CreateLogfile(char const*)'
Logfile.o(.text+0x40e):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:14: first defined here
main.o(.text+0x576): In function `ZN8CLogfile7TextoutEiPKc':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:49: multiple definition of `CLogfile::Textout(int, char const*)'
Logfile.o(.text+0x576):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:49: first defined here
main.o(.text+0x6fe): In function `ZN8CLogfile8fTextoutEiPKcz':

C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:90: multiple definition of `CLogfile::fTextout(int, char const*, ...)'
Logfile.o(.text+0x6fe):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:90: first defined here
main.o(.text+0x758): In function `ZN8CLogfile8fTextoutEibPKcz':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:101: multiple definition of `CLogfile::fTextout(int, bool, char const*, ...)'
Logfile.o(.text+0x758):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:101: first defined here
main.o(.text+0x7c0): In function `ZN8CLogfile14FunctionResultEPKcb':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:111: multiple definition of `CLogfile::FunctionResult(char const*, bool)'
Logfile.o(.text+0x7c0):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:111: first defined here
main.o(.text+0x5aa): In function `ZN8CLogfile7TextoutEibPKc':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:55: multiple definition of `CLogfile::Textout(int, bool, char const*)'
Logfile.o(.text+0x5aa):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:55: first defined here
main.o(.text+0x6ac): In function `ZN8CLogfile8fTextoutEPKcz':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:81: multiple definition of `CLogfile::fTextout(char const*, ...)'
Logfile.o(.text+0x6ac):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:81: first defined here
main.o(.text+0x4ba): In function `ZN8CLogfile10WriteTopicEPKci':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:32: multiple definition of `CLogfile::WriteTopic(char const*, int)'
Logfile.o(.text+0x4ba):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:32: first defined here
main.o(.text+0x540): In function `ZN8CLogfile7TextoutEPKc':
C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:43: multiple definition of `CLogfile::Textout(char const*)'
Logfile.o(.text+0x540):C:/Programme/Dev-Cpp/Projekte/Logfile/Logfile.cpp:43: first defined here
collect2: ld returned 1 exit status

make.exe: *** [Logfile.exe] Error 1

Ausführung beendet

ChrisJ

Alter Hase

Beiträge: 487

Wohnort: Schweich

Beruf: Schüler

  • Private Nachricht senden

2

06.01.2008, 13:42

Binde in der main.cpp mal anstatt CLogfile.cpp die CLogfile.hpp ein.
"Don't trust your eyes: They are a hell of a lot smarter than you are"

3

06.01.2008, 13:46

Geil hat geklappt aber vorher wurde jede Datei doch auch nur einmal eingebunden oder??

4

06.01.2008, 14:50

Man inkludiert niemals Source-Dateien, immer die Header-Dateien!

Nebenbei ... warum Textout(int, ...) statt Textout(FONTCOLORS const&, ...) ?
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

5

06.01.2008, 17:30

Stand so im buch habs einfach stumpf abgetippt...

Faule Socke

Community-Fossil

Beiträge: 1 915

Wohnort: Schreibtischstuhl

  • Private Nachricht senden

6

06.01.2008, 17:47

Zum Thema abtippen: Ich finde das in den büchern und tuts sowieso etwas komischt. Überm code steht ne grobe beschreibung, und der code ist dann ganz ausführlich mit dingen, die im text net erwähnt worden sind. der lerneffekt wäre viel größer, wenn oben drüber steht, was genau man machen soll, und wenn man das net schafft, kann man den code angucken... ich mach grade nochmal die irrlicht tuts da nervt das etwas, da will man was selber machen, anstatt einfach nur abzutippen und dann ist der text so unausführlich, dass man in code gucken muss...

Zum festigen auf jeden fall nochmal kleine projekte anlegen und das gelernte üben.(Hab zum beispiel ausm kopf grade eins geschrieben, das nen modell lädt und nen licht drum rum kreisen lässt... dann weiss ich immer das ichs kapiert hab)

Socke

7

07.01.2008, 16:26

Wenn ich mit dem Kapitel fertig bin, probier ichs auch meitens selbst,nur muss
ichs erstmal verstanden haben und dafür brauch ich eben häufig das fertige Programm(wie schon erwähnt).

Werbeanzeige