In function `__static_initialization_and_destruction_0': multiple definition of `Column::Names' first defined here

Hello all,

I am getting the below error while trying to compile C++ files.

CC -O -pthread -w -g -I. -I/<<dirpath>>/src/global/include -I/<<dirpath>>/src/gias/include Datagrid.cc /<<dirpath>>/src/grid/obj/Datagrid.o -o Datagrid
/<<dirpath>>/src/grid/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/<<dirpath>>/src/grid/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::Names'
/tmp/cc2TOxqD.o:/<<dirpath>>/src/grid/src/datagrid/Datagrid.cc:12170: first defined here
/<<dirpath>>/src/grid/obj/Datagrid.o: In function `charArray':
/<<dirpath>>/src/grid/include/DataGrid.h:602: multiple definition of `Column::DbNames'
/tmp/cc2TOxqD.o:/<<dirpath>>/src/grid/include/DataGrid.h:602: first defined here

In the file DataGrid.cc we are adding the below
1
2
charArray Column::Names;
charArray Column::DbNames;


And in file DataGrid.h we have the below code, there is much more code i am just copying the relevant code.
*** EDITED THE CODE BELOW MISSED SOME CODE PREVIOUSLY
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
class DataGrid;
class DataList;
class DataRowArray;
class DataRow;
class ColumnArray;
class Column;
class charArray;

class charArray
{
private:
    inline charArray( const charArray &rhs );
    void buildNew(){}

public:

    inline charArray()
    {};

    inline charArray( const int _sz )
    {}

    inline char * &operator[](int index)
    {};

    inline char * &operator[](int index) const
    {};

    inline int size( void ) const{};

    inline int getCurrSize( void ) { };

    inline char * & back(void){};

    inline void pop_back(void){};

    inline void push_back( char *_newObjPtr ){};
};//class charArray

class Column
{
private:

    static charArray Names;
    static charArray DbNames;

    inline static char * addName( char *_candidate ){};

    inline static char * addDbName( char *_candidate ){};

public:
    
    friend class DataGrid;
    friend class db2Context; 
 
    inline Column( char *_dbName,  
        char *_name,     
        char *_database, 
        char *_len,      
        char *_colType,  
        char *_dataType  
        )
    {

    };

    inline Column( void ){};

    inline ~Column(){}

    inline Column( const Column &rhs ){}

    inline char *getName( void )         { return name; };
    inline const char *getDbName( void ) { return dbName; };
    inline char *getDatabase( void )     { return database; };

    inline void setLink( char * _link )
    {

    };

    inline void assign_members(
        char *_dbName,
        char *_name,
        char *_database,
        char *_len,
        char *_font,
        char *_fontSize,
        char *_color,
        char *_colType,
        char *_dataType
        )
    {
 
    };

    inline void assignMembers(
        char *_dbName,
        char *_name,
        char *_database,
        char *_len,
        char *_font,
        char *_fontSize,
        char *_color,
        char *_colType,
        char *_dataType
        )
    {
    };

};//class Column  


Many thanks for your help.

Note: this code was compiling fine in Solaris environment I am trying to migrate it to Linux 64 bit where it is giving problems
Last edited on
One of the messages points out function charArray. Show it.
Also it is not seen how files of your project are grouped.
Last edited on
what is on the line 602 of DataGrid.h?

The Sun compiler is probably the worst of the modern C++ compilers (which is offset by their excellent debugging tools), no surprise that Solaris-only code isn't portable.
Vlad,

charArray is a class defined in DataGrid.h file I have edited the previous code (previously i missed it)

How do I check about grouping of files in the project ? (My apologies i am not very familiar with C++)

Cubbi,
On line 602 there is a different code I don't know why at compilation time the compiler is giving different line numbers

On line 602 i have this line "sizeOfMe = 0; "

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

class charArray
{
private:
    inline charArray( const charArray &rhs );
    char **ptr;
    int  allocSize;
    int  sizeOfMe;
    int  allocMult;
    void buildNew()
    {
        ptr = new char *[allocSize];

        for( int anakin = 0 ; anakin < sizeOfMe ; anakin++ )
            ptr[ anakin ] = NULL;
    }
public:

    inline charArray()
    {
        allocMult = allocSize = 15;
        sizeOfMe = 0;            ///////////////  LINE 602 //////////////
        this->buildNew();

   };//inline charArray()


Also , thanks once again, last time I followed your suggesion on few changes regarding migrating the code from Solaris to Linux and was able to resolve few initial errors.
Last edited on
By word group I meant how you are including files in each other with the derictive #include.

It is totally unclear what files you have and how they are grouped.
Last edited on
Vlad,
Thanks, below is how the files pertaining to this error are grouped.

DataGrid.cc includes DataGrid.h
DataGrid.h includes textConv.h
textConv.h includes cgic.h

The compiler is complaining about

1
2
3
4
5
6
7
CC -O -pthread -w -g -I. -I/<<dirpath>>/src/global/include -I/<<dirpath>>/src/gias/include Datagrid.cc /<<dirpath>>/src/grid/obj/Datagrid.o -o Datagrid
/<<dirpath>>/src/grid/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/<<dirpath>>/src/grid/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::Names'
/tmp/cc2TOxqD.o:/<<dirpath>>/src/grid/src/datagrid/Datagrid.cc:12170: first defined here
/<<dirpath>>/src/grid/obj/Datagrid.o: In function `charArray':
/<<dirpath>>/src/grid/include/DataGrid.h:602: multiple definition of `Column::DbNames'
/tmp/cc2TOxqD.o:/<<dirpath>>/src/grid/include/DataGrid.h:602: first defined here


As i can see in the C++ code "charArray" and "Column" are classes defined inside "DataGrid.h", we are trying get object (Names) of class charArray from Column class(as per my understanding) something like below.

1
2
charArray Column::Names;
charArray Column::DbNames;


Inside "Column" class there is a private scoped charArray reference/object declared with name "Names" something like below.
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
(...Code Snippet from "DataGrid.h".....)
class Column //Column Class
{
private:

    static charArray Names;  ///// its trying to refer this.
    static charArray DbNames;

    inline static char * addName( char *_candidate ){};

    inline static char * addDbName( char *_candidate ){};

public:
    
    friend class DataGrid;
    friend class db2Context; 
 
    inline Column( char *_dbName,  
        char *_name,     
        char *_database, 
        char *_len,      
        char *_colType,  
        char *_dataType  
        )
    {

    };

    inline Column( void ){};

    inline ~Column(){}

    inline Column( const Column &rhs ){}

    inline char *getName( void )         { return name; };
    inline const char *getDbName( void ) { return dbName; };
    inline char *getDatabase( void )     { return database; };

    inline void setLink( char * _link )
    {

    };

    inline void assign_members(
        char *_dbName,
        char *_name,
        char *_database,
        char *_len,
        char *_font,
        char *_fontSize,
        char *_color,
        char *_colType,
        char *_dataType
        )
    {
 
    };

    inline void assignMembers(
        char *_dbName,
        char *_name,
        char *_database,
        char *_len,
        char *_font,
        char *_fontSize,
        char *_color,
        char *_colType,
        char *_dataType
        )
    {
    };

};//class Column    



The DataGrid.cc file do not have main() method nither do any of the involved files, after I did a bit of research on google i found out that if a file don't have a main() method then at the time of making executable it would give us an error like below.

1
2
3
4
5
(...........Error Message .................)
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x18): In
function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status


To resolve this I gave -c option while compiling the code and all the above errors went away.
But now i can see below message comming up in my log.

 
obj/Datagrid.o: linker input file unused because linking not done


Is this message alright or it's some kind of different error which is hiding previous errors.?
Sorry about creating confusion here , I should have mentioned that my files don't have a main() method ..
Topic archived. No new replies allowed.