Brauche Hilfe - Linkererror



  • Guten Tag.

    Ich habe ein kleines Problem beim Kompilieren.
    Und zwar kommt beim Kompilieren folgende Meldung:

    gcc -pipe -g -O1 -W -pg -fPIC -L. -Wl,-rpath,. parsePLY.o glutwindow.o pixel.o ppmwriter.o rgb.o point.o vector.o matrix.o fileloader.o 
    sceneFactory.o shapeFactory.o transformFactory.o lightFactory.o materialFactory.o textureFactory.o settingFactory.o scene.o material.o 
    light.o camera.o shape.o composite.o geometry.o box.o sphere.o triangle.o 
    cylinder.o torus.o cone.o mesh.o triangleMesh.o raytracer.o lightmodel.o ray.o
     rootFinder.o bumpMap.o textureMap2D.o ply.o -o ../main main.o -lglut -lboost_thread -L../ -Wl,-rpath,.
    main.o:(.data.rel.local+0x0): multiple definition of `elem_names'
    parsePLY.o:(.data.rel.local+0x0): first defined here
    main.o:(.data.rel.local+0x20): multiple definition of `vert_props'
    parsePLY.o:(.data.rel.local+0x20): first defined here
    main.o:(.data.rel.local+0xa0): multiple definition of `face_props'
    parsePLY.o:(.data.rel.local+0xa0): first defined here
    collect2: ld gab 1 als Ende-Status zurück
    

    Ich weiß einfach nicht warum das so sein sollte. Sobald ich in irgendeiner Datei die parsePLY.hpp includieren will kommt deiser Fehler.

    Ich habe schon geschaut, ob die Präprozessordirektiven stimmen. Das tun sie.
    Dann hab ich schon komplett alle .o Dateien erneuern lassen. Das hat leider auch nichts gebracht.
    Das kuriose ist, dass dieser Code so schon einmal kompiliert hat?!?
    Hier mal die Datei parsePLY.hpp:

    #ifndef PARSEPLY_HPP
    #define PARSEPLY_HPP
    
    #include <ply.h>
    #include <string>
    #include <point.hpp>
    #include <iostream>
    #include <vector>
    #include <stdio.h>
    #include <stdlib.h>
    
    /* user's vertex and face definitions for a polygonal object */
    
    typedef struct Vertex {
      float x,y,z;             /* the usual 3-space position of a vertex */
    } Vertex;
    
    typedef struct Face {
      unsigned char intensity; /* this user attaches intensity to faces */
      unsigned char nverts;    /* number of vertex indices in list */
      int *verts;              /* vertex index list */
    } Face;
    
    /* information needed to describe the user's data to the PLY routines */
    
    char *elem_names[] = { /* list of the kinds of elements in the user's object */
      "vertex", "face"
    };
    
    PlyProperty vert_props[] = { /* list of property information for a vertex */
      {"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0},
      {"y", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,y), 0, 0, 0, 0},
      {"z", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,z), 0, 0, 0, 0},
    };
    
    PlyProperty face_props[] = { /* list of property information for a vertex */
      {"intensity", PLY_UCHAR, PLY_UCHAR, offsetof(Face,intensity), 0, 0, 0, 0},
      {"vertex_indices", PLY_INT, PLY_INT, offsetof(Face,verts),
       1, PLY_UCHAR, PLY_UCHAR, offsetof(Face,nverts)},
    };
    
    class parsePLY {
      private:
       std::string filename_;
       // Vertexlist
       std::vector<math3d::point *> vertexes_;
       int i,j,k;
       PlyFile *ply;
       int nelems;
       char **elist;
       int file_type;
       float version;
       int nprops;
       int num_elems;
       PlyProperty **plist;
       Vertex **vlist;
       Face **flist;
       char *elem_name;
       int num_comments;
       char **comments;
       int num_obj_info;
       char **obj_info;
    
      public:
        parsePLY(std::string file);
        void readPLY();
    };
    
    #endif
    

    Ich weiß, ich könnte diese dateien als extern deklarieren und in der cpp definieren. Das hab ich aber auch schon probiert.

    Was auch nicht sein kann ist, dass 2 mal die selbe Datei beim Linken der main angegeben ist.
    Nicht auf den alten C-Code schauen, der PLY-Reader ist nun mal nur in C geschrieben worden. Das ist normal, erzeugt aber ein paar Warnungen.

    Grüße

    PS: hier mal noch das Bildchen von Doxygen, wo die datei überall Includiert ist:
    http://www.php-dir.de/parsePLY_8hpp__dep__incl.png



  • Wenn du den Header inkludierst, wird in jeder Uebersetzungseinheit ensprechend ein Element mit Namen elem_names, ... angelegt. Ob da nun extern davorsteht oder nicht. Moeglicher Fix: Schiebe die entsprechenden Sachen in genau eine cpp-Datei, deklariere in den anderen cpp-Dateien diese mit extern und lass die Deklaration in den Header ganz einfach weg.



  • Und ich danke 🙂
    Das wars 🙂
    Manchmal ist man einfach blind


Anmelden zum Antworten