In function `__static_initialization_and_destruction_0' multiple definition of first defined here

Hello All,

I am getting the below error while trying to compile my C++ code on Linux, I would appriciate if anybody could help me figure out how to solve this.

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
g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include     Datagrid.cc /home/myhome/ia-k_L/src/gias/obj/Datagrid.o   -o Datagrid
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::Names'
/tmp/cc3cQa7z.o:/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `charArray':
/home/myhome/ia-k_L/src/gias/include/DataGrid.h:602: multiple definition of `Column::DbNames'
/tmp/cc3cQa7z.o:/home/myhome/ia-k_L/src/gias/include/DataGrid.h:602: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x0): multiple definition of `Column::default_link'
/tmp/cc3cQa7z.o:(.data+0x0): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x14): multiple definition of `Column::default_font'
/tmp/cc3cQa7z.o:(.data+0x14): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x1a): multiple definition of `Column::default_fontSize'
/tmp/cc3cQa7z.o:(.data+0x1a): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x20): multiple definition of `Column::default_fontColor'
/tmp/cc3cQa7z.o:(.data+0x20): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x30): multiple definition of `Column::default_color'
/tmp/cc3cQa7z.o:(.data+0x30): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x40): multiple definition of `Column::default_verAlignment'
/tmp/cc3cQa7z.o:(.data+0x40): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x48): multiple definition of `Column::default_horAlignment'
/tmp/cc3cQa7z.o:(.data+0x48): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::default_numDec'
/tmp/cc3cQa7z.o:/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x60): multiple definition of `fdTypeCodes'
/tmp/cc3cQa7z.o:(.data+0x60): first defined here
/xenv/GCC/X/4.1.2r5_64/RH5.6AS_64/usr/bin/../lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
ia64make[4]: *** [Datagrid] Error 1


Many thanks for your help..
¿Why are you linking the same file twice?
ne555 you mean this command right?

g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include Datagrid.cc /home/myhome/ia-k_L/src/gias/obj/Datagrid.o -o Datagrid

The makefile is issuing this command don't know why and where, in solaris makefile behaviour is different then in Linux.

Now i am using GNU makefile on RH linux previously it was some other version on Solaris.
The make file is something like below, also don't know why one of the dependency is calling the same make file inside itself some think like this "$(GIAS_DATAGRID)/makefile" , this is basicaly pointing to same makefile it is in.. I guess it could be to check if the make file was changed(different timestamp)

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
Datagrid    : $(GIAS_OBJ)/Datagrid.o
tableEngine : $(GIAS_OBJ)/tableEngine.o
navBuilder  : $(GIAS_OBJ)/navBuilder.o
portfolio   : $(GIAS_OBJ)/portfolio.o
product     : $(GIAS_OBJ)/product.o 
textConv    : $(GIAS_OBJ)/textConv.o 
gridHelper  : $(GIAS_OBJ)/gridHelper.o 
logFile     : $(GIAS_OBJ)/logFile.o 


## Object Rules

$(GIAS_OBJ)/Datagrid.o : $(OLI_GLOBAL_OBJ)/cgic.o $(GIAS_DATAGRID)/Datagrid.cc $(GIAS_INC)/DataGrid.h
	
	$(MYCC) -c $(GIAS_DATAGRID)/Datagrid.cc -o $(GIAS_OBJ)/Datagrid.o
	
	
$(GIAS_OBJ)/tableEngine.o : $(GIAS_OBJ)/Datagrid.o $(GIAS_DATAGRID)/tableEngine.cc $(GIAS_INC)/tableEngine.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/tableEngine.cc -o $(GIAS_OBJ)/tableEngine.o

$(GIAS_OBJ)/navBuilder.o : $(GIAS_DATAGRID)/navBuilder.cc $(GIAS_INC)/navBuilder.h $(GIAS_INC)/htmlBuilder.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/navBuilder.cc -o $(GIAS_OBJ)/navBuilder.o

$(GIAS_OBJ)/portfolio.o : $(GIAS_DATAGRID)/portfolio.cc $(GIAS_INC)/portfolio.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/portfolio.cc -o $(GIAS_OBJ)/portfolio.o

$(GIAS_OBJ)/product.o : $(GIAS_DATAGRID)/product.cc $(GIAS_INC)/product.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/product.cc -o $(GIAS_OBJ)/product.o

$(GIAS_OBJ)/textConv.o : $(GIAS_DATAGRID)/textConv.cc $(GIAS_INC)/textConv.h $(GIAS_INC)/conversionTables.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/textConv.cc -o $(GIAS_OBJ)/textConv.o

$(GIAS_OBJ)/gridHelper.o : $(GIAS_OBJ)/Datagrid.o  $(GIAS_DATAGRID)/gridHelper.cc $(GIAS_INC)/gridHelper.h $(GIAS_INC)/gridHelper.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/gridHelper.cc -o $(GIAS_OBJ)/gridHelper.o

$(GIAS_OBJ)/logFile.o : $(GIAS_DATAGRID)/logFile.cc $(GIAS_INC)/logFile.h $(GIAS_INC)/transactionTypes.h $(GIAS_DATAGRID)/makefile
	
	$(MYCC) -c $(GIAS_DATAGRID)/logFile.cc -o $(GIAS_OBJ)/logFile.o


Would really appriciate if some one can let know whats going wrong here...

Many thanks in advace.
I don't think that you should have *.o as a dependency for others *.o
¿Where are the build commands for `Datagrid'? I only see the dependencies.
Make file is calling some impilicit command after the target is finished building don't know why is it behaving that way. below is full code from make file , I removed the unessary echo messages. but kept this echo message "Done with building Datagrid.o" this will say that target finished building then don't know why another command is getting executed after this.
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
include $(ROOT)/MacroRules
include $(ROOT)/LocalRules
LIBS=$(GIAS_LIB) $(OLI_GLOBAL_LIB)
INCDIRS= -I. -I$(OLI_GLOBAL_INC) -I$(GIAS_INC) 
MYCC=g++ -O -pthread -g $(INCDIRS)
CC=g++
CXXFLAGS=-O -pthread -g $(INCDIRS)

install : preinstall
	@echo "ia:src:gias:src:datagrid nothing to install"

preinstall :
	@echo "ia:src:gias:src:datagrid nothing to preinstall"

all : \
	Datagrid \
	tableEngine \
	navBuilder \
	portfolio \
	product \
	textConv \
	gridHelper \
	logFile

Datagrid    : $(GIAS_OBJ)/Datagrid.o
tableEngine : $(GIAS_OBJ)/tableEngine.o
navBuilder  : $(GIAS_OBJ)/navBuilder.o
portfolio   : $(GIAS_OBJ)/portfolio.o
product     : $(GIAS_OBJ)/product.o 
textConv    : $(GIAS_OBJ)/textConv.o 
gridHelper  : $(GIAS_OBJ)/gridHelper.o 
logFile     : $(GIAS_OBJ)/logFile.o 

## Object Rules
$(GIAS_OBJ)/Datagrid.o : $(OLI_GLOBAL_OBJ)/cgic.o $(GIAS_DATAGRID)/Datagrid.cc $(GIAS_INC)/DataGrid.h
	
	$(MYCC) -c $(GIAS_DATAGRID)/Datagrid.cc -o $(GIAS_OBJ)/Datagrid.o
	
	@echo "Done with building Datagrid.o"


Below is the complete log pertaining to DataGrid build I removed echo message from here
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
ia64make[4]: Entering directory `/home/myhome/ia-k_L/src/gias/src/datagrid'
--
ia:src:gias:src:datagrid building    datagrid.o

g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include  -c /home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc -o /home/myhome/ia-k_L/src/gias/obj/Datagrid.o
Done with building Datagrid.o
g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include     Datagrid.cc /home/myhome/ia-k_L/src/gias/obj/Datagrid.o   -o Datagrid
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::Names'
/tmp/ccQgHfWe.o:/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `charArray':
/home/myhome/ia-k_L/src/gias/include/DataGrid.h:602: multiple definition of `Column::DbNames'
/tmp/ccQgHfWe.o:/home/myhome/ia-k_L/src/gias/include/DataGrid.h:602: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x0): multiple definition of `Column::default_link'
/tmp/ccQgHfWe.o:(.data+0x0): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x14): multiple definition of `Column::default_font'
/tmp/ccQgHfWe.o:(.data+0x14): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x1a): multiple definition of `Column::default_fontSize'
/tmp/ccQgHfWe.o:(.data+0x1a): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x20): multiple definition of `Column::default_fontColor'
/tmp/ccQgHfWe.o:(.data+0x20): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x30): multiple definition of `Column::default_color'
/tmp/ccQgHfWe.o:(.data+0x30): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x40): multiple definition of `Column::default_verAlignment'
/tmp/ccQgHfWe.o:(.data+0x40): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x48): multiple definition of `Column::default_horAlignment'
/tmp/ccQgHfWe.o:(.data+0x48): first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o: In function `__static_initialization_and_destruction_0':
/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: multiple definition of `Column::default_numDec'
/tmp/ccQgHfWe.o:/home/myhome/ia-k_L/src/gias/src/datagrid/Datagrid.cc:12170: first defined here
/home/myhome/ia-k_L/src/gias/obj/Datagrid.o:(.data+0x60): multiple definition of `fdTypeCodes'
/tmp/ccQgHfWe.o:(.data+0x60): first defined here
/xenv/GCC/X/4.1.2r5_64/RH5.6AS_64/usr/bin/../lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
ia64make[4]: *** [Datagrid] Error 1
ia64make[4]: Leaving directory `/home/myhome/ia-k_L/src/gias/src/datagrid'


With build commands for Datagrid do you mean this command "g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include Datagrid.cc /home/myhome/ia-k_L/src/gias/obj/Datagrid.o -o Datagrid" this is getting executed implicitly by make and its giving the problem..
Update from my side, I was able to disable the implicit behaviour of make by adding ".SUFFIXES:" and the implicit compile command g++ -O -pthread -g -I. -I/home/myhome/ia-k_L/src/global/include -I/home/myhome/ia-k_L/src/gias/include Datagrid.cc /home/myhome/ia-k_L/src/gias/obj/Datagrid.o -o Datagrid

is no longer comming.
Topic archived. No new replies allowed.