Duplicate symbol _main?

So this is a really strange error for me. I am not new to C++, but I have never taken a course. I pretty much learned everything I did from this site and a few others. The areas I am weakest at are compiler issues and debugging.

That being said, I am trying to help an associate, an elderly gentleman, with their code. I get an error as in the title when I try to compile, but I have verified every single file, and I only have a single main() function in the file sundarmain.c .

Here is the code for the main script:

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
#ifndef sundarmain_c
#define sundarmain_c

/* Driver for routine vegas */

#define NRANSI
#include "subroutines.h"
#include "sundarmain.h"
#include "subs.h"
#include "sundarf2.h"
#include "dnr.h"
#include "dnrutil.h"
#include "sundarcom.h"


int main()
{
	long init,itmax,j,ncall,nprn,itype;
	double avgi,chi2a,sd,xoff;
	double *regn;
	if ((data_file = fopen("vegas.dat","r")) == NULL) nrerror("data file Error"); 
	output_file = fopen("vegas.out","w");
	summary_file = fopen("vegas.sum","w");
	plot_file = fopen("vegas.plot","w");
 
	regn=vector(1,20);
	idum = -10;
	ReadLong(&itype,"itype");	
	ReadLong(&ndim,"ndim");	
	ReadDouble(&xoff,"xoff");
	ReadLong(&ncall,"ncall");
	ReadLong(&itmax,"itmax");	
	ReadLong(&nprn,"nprn");	
	ReadLong(&iwrite,"iwrite");	
		avgi=sd=chi2a=0.0;
		for (j=1;j<=ndim;j++) 
		{
			regn[j]=0.0;
			regn[j+ndim]=1.0;
		}
		init = -1;
	if (itype == 0)	vegas(regn,ndim,fxn,init,ncall,itmax,nprn,&avgi,&sd,&chi2a); /* checking version */
	if (itype == 1)	vegas(regn,ndim,func,init,ncall,itmax,nprn,&avgi,&sd,&chi2a); /* real version */
		printf("Number of iterations performed: %d\n",itmax);
		printf("Integral, Standard Dev., Chi-sq. = %12.6f %12.6f% 12.6f\n",
			avgi,sd,chi2a);
		fprintf(output_file,"Number of iterations performed: %d\n",itmax);
		fprintf(output_file," Standard Dev., Chi-sq. = %12.6f %12.6f% 12.6f\n",avgi,sd,chi2a);
		init = 1;
		if (itype == 0)	vegas(regn,ndim,fxn,init,ncall,itmax,nprn,&avgi,&sd,&chi2a); /* checking version */
	if (itype == 1)	vegas(regn,ndim,func,init,ncall,itmax,nprn,&avgi,&sd,&chi2a); /* real version */
	fprintf(output_file,"Additional iterations performed: %d \n",itmax);
		fprintf(output_file,"Integral, Standard Dev., Chi-sq. = %12.6f %12.6f% 12.6f\n",
			avgi,sd,chi2a);
			exit(1);
	free_vector(regn,1,20);
	printf("Normal completion\n");
	return 0;
}
#undef NRANSI
#endif 


And here is my makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NAME = sundarmain.exe

OBJECTS = $(NAME:.exe=.o) sundarmain.o subs.o sundarf2.o dnrutil.o

CPPFLAGS = -I/usr/local/include

HEADERS = sundarcom.h subroutines.h dnrutil.h subs.h sundarf2.h dnr.h dnrutil.h sundarmain.h

all:	$(NAME)

$(OBJECTS): $(HEADERS)

$(NAME): $(OBJECTS)
	g++ -o $(NAME) -O $(OBJECTS) -L/usr/local/lib

.cpp.o:
	g++ -c -O $(CPPFLAGS) $*.cpp


And here is the program output:

cc  -I/usr/local/include  -c -o sundarmain.o sundarmain.c
cc  -I/usr/local/include  -c -o subs.o subs.c
cc  -I/usr/local/include  -c -o sundarf2.o sundarf2.c
cc  -I/usr/local/include  -c -o dnrutil.o dnrutil.c
g++ -o sundarmain.exe -O sundarmain.o sundarmain.o subs.o sundarf2.o dnrutil.o -L/usr/local/lib
ld: duplicate symbol _main in sundarmain.o and sundarmain.o
collect2: ld returned 1 exit status
make: *** [sundarmain.exe] Error 1


How can I have a duplicate _main in sundarmain.o, if it is first defined in sundarmain?

I do have a declaration in the header file of int main(), but I get the same error even if I take that out.

Any help would be greatly appreciated. The person I am helping was one of my favourite professors (not a programming course, hehe), and I would really like to be able to help him get his code working.
This line looks suspicious
OBJECTS = $(NAME:.exe=.o) sundarmain.o subs.o sundarf2.o dnrutil.o

Oh... my... gosh... Duh. Thanks!
Topic archived. No new replies allowed.