473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Linking a library with main.cpp

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

Jan 28 '07 #1
2 1962
Luigi Malagň wrote:
>
/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

--
Maksim A Polyanin
Jan 28 '07 #2
Grizlyk ha scritto:
Luigi Malagň wrote:
>/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
Jan 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LinuxN00b | last post by:
Hey, I have a problem linking Xerces-c (Apache's XMLParser) with my program. Here is a copy of my makefile. # CXX is for GNU make, CCC is for Solaris make # Define the default compiler to...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
3
by: Thomas Ruschival | last post by:
Hi, as far as I know I can link all C libraries in C++ as well. but I can't get it done with pslib. pslib is a library to create Postscript documents. The exactly same code compiles and links...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
1
by: Peetah_junkmail | last post by:
Hi, I'm not sure this is completely a C related question since it's more about linking problems, so don't hesitate to redirect me to a more appropriate NG. I have a set of useful functions...
7
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with...
3
by: walkeraj | last post by:
I'm trying to compile an open source game called IVAN , and I'm able to compile it from a makefile, but not from an IDE. I have attempted to recreate the way the makefile compiles the project as...
2
by: Mohsen A. Momeni | last post by:
Hi, Does it have any difference in security, whether to compile a function as a static lib and link it with a program or just add the function to the source? In other words, suppose we have two...
1
by: Jaco Naude | last post by:
Hi, I'm using a static library in my application which links fine except for a few global variables. The static library only contains a bunch of .cpp and .h files and the global variables are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.