already defined...



  • sers.
    also ich habn problem.

    in einer header datei habe ich eine Struktur definiert. Diese wird von main.cpp und xyz.cpp benutzt. dadurch erhalte ich den fehler:

    Linking...
    main.obj : error LNK2005: "struct _gmxLine *  gmxLines" (?gmxLines@@3PAU_gmxLine@@A) already defined in geomathix.obj
    Debug/geomathix.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.
    Creating browse info file...
    
    geomathix.exe - 2 error(s), 0 warning(s)
    

    was kann ich dagegen machen?



  • Schreib einfach static vorne dran.

    /E: Ups hab mich verlesen

    Sowas umgeht man mit

    #ifndef __MYFILENAME_H_INCLUDED__
    #define __MYFILENAME_H_INCLUDED__

    // Hier alles rein

    #endif

    [ Dieser Beitrag wurde am 20.09.2002 um 15:57 Uhr von Nemesyzz editiert. ]



  • muss ich das in meine include datei schreiben?
    da funktioniert es nämlich nicht...

    tdm danke 😞



  • So dachte ich:

    #ifndef __MYFILENAME_H_INCLUDED__
    #define __MYFILENAME_H_INCLUDED__
    
    // Hier alles rein
    struct gmxLines
    {
      POINT a;
      POINT b;
    };
    
    #endif
    


  • kann man eigentlich strukuren als parameter für funktionen übergeben??

    alles was ich machen will ist das ich z.B. eine struktur habe welche in einer headerdatei steht:

    struct xyz
    {
    ..
    ..
    };

    dann in einer cpp datei möchte ich variablen definieren:
    struct xyz var1;

    und dann habe ich noch eine funktion:
    void blabla(struct xyz var2){
    ...
    }

    diese ist in der headerdatei definiert in der auch die Struktur steht:
    void blabla(struct xyz var2);

    aber was mach ich falsch?
    danke im v.



  • struct MeinStruct
    {
      CString a;
      int b;
      double c;
    }
    
    void machwas(MeinStruct x)
    {
    }
    


  • ok so hab ichs jetzt.

    nur wie erstell ich nun die variable.
    wenn ich:

    struct _gmxLines gmxLines[50];
    

    schreibe bekomme ich

    Compiling...
    geomathix.cpp
    D:\Projekte\geomathix\geomathix.cpp(16) : error C2262: 'gmxLines' : cannot be destroyed
    D:\Projekte\geomathix\geomathix.cpp(16) : error C2133: 'gmxLines' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(62) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(62) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(62) : error C2228: left of '.index' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(66) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(66) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(66) : error C2228: left of '.index' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(67) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(67) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(67) : error C2228: left of '.x1' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(68) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(68) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(68) : error C2228: left of '.y1' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(69) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(69) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(69) : error C2228: left of '.x2' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(70) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(70) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(70) : error C2228: left of '.y2' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(71) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(71) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(71) : error C2228: left of '.color' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(72) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(72) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(72) : error C2228: left of '.description' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(101) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(101) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(101) : error C2228: left of '.index' must have class/struct/union type
    D:\Projekte\geomathix\geomathix.cpp(102) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(102) : error C2664: 'gmxDrawLine' : cannot convert parameter 1 from 'struct _gmxLines' to 'struct _gmxLine'
            Source or target has incomplete type
    D:\Projekte\geomathix\geomathix.cpp(173) : error C2036: 'struct _gmxLines *' : unknown size
    D:\Projekte\geomathix\geomathix.cpp(173) : error C2027: use of undefined type '_gmxLines'
            D:\Projekte\geomathix\geomathix.cpp(16) : see declaration of '_gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(173) : error C2228: left of '.index' must have class/struct/union type
    Error executing cl.exe.
    
    geomathix.exe - 34 error(s), 0 warning(s)
    

    wenn ich:

    _gmxLines gmxLines[50];
    

    schreibe bekomme ich

    ------------------Configuration: geomathix - Win32 Debug--------------------
    Compiling...
    geomathix.cpp
    D:\Projekte\geomathix\geomathix.cpp(16) : error C2146: syntax error : missing ';' before identifier 'gmxLines'
    D:\Projekte\geomathix\geomathix.cpp(16) : error C2501: '_gmxLines' : missing storage-class or type specifiers
    D:\Projekte\geomathix\geomathix.cpp(16) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    Creating browse info file...
    BSCMAKE: error BK1506 : cannot open file '.\Debug\geomathix.sbr': No such file or directory
    Error executing bscmake.exe.
    
    geomathix.exe - 4 error(s), 0 warning(s)
    

    sry das ich mich soooo dumm anstell!
    danke!

    [ Dieser Beitrag wurde am 20.09.2002 um 16:35 Uhr von paranoiac editiert. ]



  • noch mal ne übersicht:

    main.cpp

    // Includes
    #include <windows.h>
    #include "geomathix.h"
    ..
    ..
    

    hier wird die Struktur nicht benötigt aber andere Sachen aus der datei "geomathix.h"

    geomathix.h

    #include <windows.h>
    
    #ifndef __GEOMATHIX_H_INCLUDED__
    #define __GEOMATHIX_H_INCLUDED__
    // Structures
    // Linienstruktur
    struct _gmxLine
    {
        int index;
        int x1;
        int x2;
        int y1;
        int y2;
        int gradient;
        char description[64];
        COLORREF color;
    };
    #endif
    
    // Functions
    int gmxDrawLine(_gmxLine line);
    

    Struktur + Funktion

    geomathix.cpp

    // Includes
    #include <windows.h>
    #include "geomathix.h"
    #include <math.h>
    
    // Public
    int gmx_running=1;
    int gmx_cxscreen;
    int gmx_cyscreen;
    int gmx_xybord;
    int gmx_pixel;
    int gmx_xypbord;
    int gmx_lindex=-1;
    extern HWND hPubWnd;
    
    strcut _gmxLines gmxLines[50]; // so erhalte ich 34 Fehler
    // ohne struct nur 4
    
    ..
    ..
    
    // Funktion zum Linie zeichnen
    int gmxDrawLine(_gmxLine line)
    {
    ..
    ..
    
        return 0;
    }
    
    // Funktion zum Rendern aller Objekte
    int gmxRenderScene(HDC hDC)
    {
        // Rechteck und Gitter zeichnen
        Rectangle(hBufferDC, 0, 0, gmx_xybord, gmx_xybord);
        gmxDrawGrid();
    
        // Linien zeichnen aus Strucktur
        for(int i=0; i<50; i++){
            if(gmxLines[i].index > -1)
                gmxDrawLine(gmxLines[i]);
        }
    
        BitBlt(hDC, 0, 0, gmx_xybord, gmx_xybord, hBufferDC, 0, 0, SRCCOPY);
    
        return 0;
    }
    

    das war die funktion selber und der abschnitt indem sie aufgerufen wird!



  • Nicht so.
    Du musst die Struktur erst definieren und dann kannst du sie verwenden.

    // .h
    struct gmxLines
    {
      POINT a;
      POINT b;
    };
    
    // .cpp
    gmxLines lines[50];
    


  • so hab ichs doch



  • Dann würde es ja gehen!

    Hast du die Header auch eingebunden?
    Weil die Fehlermeldung schließen daraufhin das dein struct nicht bekannt ist.

    Schreib einfach mal in dein .cpp Datei:

    struct aaa ddd[5];

    Dann siehst du das du die gleichen Fehlermeldung bekommst.



  • ja muss dieses struct beim definieren jetzt hin oder nicht?
    hast du meinen beitrag oben nicht gesehen. so hab ichs und die fehler sind noch die gleichen
    😢



  • **// Includes
    #include <windows.h>
    #include "geomathix.h"
    ..
    ..

    hier wird die Struktur nicht benötigt aber andere Sachen aus der datei "geomathix.h"
    geomathix.h

    #include <windows.h>**

    Warum includierst du Windows.h doppelt? einmal in "geomathix.h" und dann includierst du "geomathix.h" und extra nochmal windows.h.

    @Nemesyzz: Nein, die Struktur ist schon bekannt, der Compiler findet sie ja. Erst beim Linken kann er das ganze nicht auflösen.

    Ziehe doch einmal spaßeshalber die Definition deiner Struktur in das cpp File, wo du sie brauchst. Dann sollte es gehen. Wenn dem so ist, dann liegt dein Fehler irgendwo dabei, das du Sachen "doppelt" includierst:

    z.B:

    Header1.h :

    #include Header2.h
    ........

    Header2.h :

    #include Header1.h
    ........

    und schwups hast du einen Linker - Fehler :). Sowas in der Richtung würde ich mal checken.



  • Original erstellt von TheBigW:
    **
    Ziehe doch einmal spaßeshalber die Definition deiner Struktur in das cpp File, wo du sie brauchst. Dann sollte es gehen.

    **

    geht ja eben nicht, da ich in dem header in dem ich auch die funktionen deklariere ja funktionen sind die diese struktur benutzen...

    danke


Anmelden zum Antworten