Multiple definition of `main'

Hi,

I got a few errors like [quote]multiple definition of `main’[/quote] hen linking a simple program. Since I didn’t know what was happening I made the program a bit simpler and tried again.

The program is just a hello wolrld program. You can copy/paste the code:

#include <iostream>
                                                                                                                             
using namespace std;
 
void hello();
  
main()
{
  hello();
}
 
void hello()
{
  cout << "hello world" << endl;
}

the thing is, to compile I used

gcc -c hello.cc
gcc -o merge merge.cc -I/usr/tools/root/pro/include merge.cc -L/usr/tools/root/pro/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lpthread -lm -ldl -rdynamic -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2 -lstdc++ -lg2c

Note that it would link all right using just

gcc -o merge merge.cc -L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2 -lstdc++ -lg2c

but I decided to try the same libraries I used in the first program.

I’m using gcc 3.2.2 in Red Had 9.0 and ROOT 3.05/07 (for reasons of compatibility I don’t know exactly about I haven’t been able to update)

I don’t know what could I be misssing. Any help is greatly appreciated

javierggt, look at your command line: you have “merge.cc” repeated twice :smiling_imp: :

gcc -c hello.cc
gcc -o merge merge.ccmerge.cc

So no wonder you get this error…

I hate when this happens. Actually I found the problem with the original program. As expected it had to do with using the wrong libraries. I was using the wrong gcc (Ithought I was using the right one, mixed libraries)

Thanks anyway

:blush: