ERLEDIGT
NEIN
NEIN
ANTWORTEN
1
1
ZUGRIFFE
1371
1371
EMPFEHLEN
-
Hallo, ich hab hier ein kleines Problem mit meinem Linker.
Ich hab mir eine Streamklasse geschrieben um damit von meinem (GUI)Programm Debugmeldungen in einer Konsole ausgeben zu können.
Jetzt bekomme ich aber einen Linkerfehler, wenn ich das conout-Objekt in meinem Hauptprogramm(Unit1.cpp) und gleichzeitig in meiner Klassendatei(igl3d.cpp) verwende.
Code :1
[Linker Warning] Public symbol '_conout' defined in both module D:\...\UNIT1.OBJ and D:\...\IGL3D.OBJ
Ich dachte eigentlich, dass sich das mit 'extern' lösen liese, aber anscheinend nicht.
Aktuell sieht es so aus:
Unit1.cpp
Code :1 2
#include "consolestream.h" // for console consoleStream conout(0); // defined in Unit1.cpp
IGL3D.cpp
Code :1 2
#include "consolestream.h" // for console extern consoleStream conout(0); // defined in Unit1.cpp
Damit kann ich in beiden Dateien mit
Code :1
conout << "test" << endl;
etwas in die Konsole schreiben.
p.s. Die Headerdatei von consolestream.h ist natürlich mit #ifdef vor mehrfacheinbindung geschützt:
Code :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
#ifndef __CONSOLE_STREAM__ #define __CONSOLE_STREAM__ #include <vcl.h> #pragma hdrstop #include <streambuf> #include <ostream> #include <string> // stream functions std::ostream& operator << (std::ostream& ostr, std::string& sstr); // consoleStreambuf class consoleStreambuf : public std::streambuf { public: consoleStreambuf(int iBuffersize=255); virtual ~consoleStreambuf(); private: void WriteCharToConsole(int); void WriteToConsole(); void DeleteConsole(); void CreateConsole(); HANDLE hConsoleOut; char* pReserve; protected: int_type overflow(int_type); int_type sync(); }; // consoleStream class consoleStream : public std::ostream { public: consoleStream(); consoleStream(int); virtual ~consoleStream(); }; #endif
-
16.12.05 12:03 #2
- Registriert seit
- Jun 2005
- Beiträge
- 8.168
Hi.
Hier initialisierst du die Variable conout (du rufst den Konstruktor auf) obwohl du gleichzeitig die Variable als extern deklariert hast. Das ist dann natürlich Quark.
Zitat von Atlanx
Leider warnt der Borland Compiler nicht vor diesem Konstrukt.
GrußIf at first you don't succeed, try again. Then quit. No use being a damn fool about it.
Ähnliche Themen
-
[VC++ 6.0] Linker Warning LNK4089
Von vfl_freak im Forum VisualStudio & MFCAntworten: 12Letzter Beitrag: 06.07.10, 15:57 -
already defined
Von Raven280438 im Forum C/C++Antworten: 10Letzter Beitrag: 27.06.10, 20:26 -
Verweis auf nicht aufgelöstes externes Symbol "_matClose_d" in Funktion ""public: sta
Von jnoessne im Forum C/C++Antworten: 3Letzter Beitrag: 09.11.09, 19:05 -
Ajax is not defined
Von Aser im Forum Javascript & AjaxAntworten: 2Letzter Beitrag: 15.08.08, 16:41 -
Fehlermeldung - must be defined in ist own file
Von WIK-Lars im Forum JavaAntworten: 1Letzter Beitrag: 19.04.07, 13:16





Zitieren
Login






