tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
1371
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Avatar von Atlanx
    Atlanx Atlanx ist offline Mitglied Bronze
    Registriert seit
    Jul 2004
    Ort
    Bayern
    Beiträge
    32
    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
     

  2. #2
    deepthroat deepthroat ist offline Mitglied Diamant
    tutorials.de Premium-User
    Registriert seit
    Jun 2005
    Beiträge
    8.168
    Hi.
    Zitat Zitat von Atlanx
    Code :
    1
    2
    
    #include "consolestream.h"  // for console
    extern consoleStream conout(0); // defined in Unit1.cpp
    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.

    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

  1. [VC++ 6.0] Linker Warning LNK4089
    Von vfl_freak im Forum VisualStudio & MFC
    Antworten: 12
    Letzter Beitrag: 06.07.10, 15:57
  2. already defined
    Von Raven280438 im Forum C/C++
    Antworten: 10
    Letzter Beitrag: 27.06.10, 20:26
  3. Antworten: 3
    Letzter Beitrag: 09.11.09, 19:05
  4. Ajax is not defined
    Von Aser im Forum Javascript & Ajax
    Antworten: 2
    Letzter Beitrag: 15.08.08, 16:41
  5. Antworten: 1
    Letzter Beitrag: 19.04.07, 13:16