Linking a library with main.cpp

  • Thread starter =?ISO-8859-15?Q?Luigi_Malag=F2?=
  • Start date
?

=?ISO-8859-15?Q?Luigi_Malag=F2?=

Hello,
i'm having a problem with "multiple definition error" linking a library.
I have a program with a main. I have another program with classes and a
main too. I created a library of the second program, after compiling, in
this way:

ar -r /path/lib/libtest.a ./Class1.o ./Class2.o ./Class3.o

Notice that from the list I excluded ./main.o !
then I copied all .h in a specific directory /path/include

Then i compiled the first program adding -I/path/include
and -L/path/lib and -ltest

In the main of the first program, I only include and use some classes
from the second program, I dont expect the first program to clash with
the main of the second program!

Of course I'm missing something, since I cannot compile the program, I
get a multiple definition error:


/path/lib/libbriantool.a(main.o): In function `main':
main.cpp:(.text+0x70): multiple definition of `main'
../main.o:main.cpp:(.text+0x70): first defined here
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
/path/lib/libbriantool.a(main.o)
collect2: ld returned 1 exit status
make: *** [..] Error 1


Thanks for your help,
Luigi
 
G

Grizlyk

Luigi said:
/path/lib/libbriantool.a(main.o): In function `main':
main.cpp:(.text+0x70): multiple definition of `main'
./main.o:main.cpp:(.text+0x70): first defined here
/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
/path/lib/libbriantool.a(main.o)
collect2: ld returned 1 exit status
make: *** [..] Error 1


ask about "/path/lib/libbriantool.a" here
 
?

=?ISO-8859-15?Q?Luigi_Malag=F2?=

Grizlyk ha scritto:
>> /path/lib/libbriantool.a(main.o): In function `main':
>> main.cpp:(.text+0x70): multiple definition of `main'
>> ./main.o:main.cpp:(.text+0x70): first defined here
>> /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/../../../../i686-pc-linux-gnu/bin/ld:
>> Warning: size of symbol `main' changed from 337 in ./main.o to 3125 in
>> /path/lib/libbriantool.a(main.o)
>> collect2: ld returned 1 exit status
>> make: *** [..] Error 1
>
>
> ask about "/path/lib/libbriantool.a" here news:gnu.g++.help


Thanks a lot, i just realize the problem could be solved setting a
specific option to the compiler/linker.

I will post the message to that newsgroup if i wont be able to solve my
problem


Luigi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top