473,654 Members | 3,098 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1969
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++.he lp

--
Maksim A Polyanin
Jan 28 '07 #2
Grizlyk ha scritto:
Luigi Malagò wrote:
>/path/lib/libbriantool.a( main.o): In function `main':
main.cpp:(.tex t+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++.he lp

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
2350
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 use for C++ programs as u++ CXX=g++
7
5104
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 normal functions in header files results in multiple definition errors even when include guards are used. -- STH Hatton's Law: "There is only One inviolable Law" KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com Mozilla:...
3
2483
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 with C and it doesn't when I use C++. This is my linking command: gcc -o test -L/usr/lib/ -lps -lstdc++ test.cpp and in /usr/lib is definitely the file /usr/lib/libps.so -> libps.so.0.2.4
20
3220
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 references to functions and objects not defined in the current translation. All such translator output is collected into a program image which contains information needed for execution in its execution environment." What I'm wondering is what exactly...
1
313
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 (let's call this SUF) that facilitates my life when coding, such as memory allocation wrappers or generic string functions. I have a project composed of a shared library (SL) and a main program (MP) using SL. For some reasons, I don't want to make a...
7
6548
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 LIBCMT(D).DLL. (My requirement is that we can't link with MSVCRT(D).LIB.) Below are steps I've followed, and the resulting problems 1. Using the New Project wizard, generate a Visual C++ .NET Class Library project (call it "Doomed") and a VC++...
3
4371
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 closely as possible, yet I'm getting odd linking errors. I think I've traced it to some kind of problem with the SDL libraries it uses, yet I can't explain why it will compile from the makefile and not from the IDE. I have made sure that the ide...
2
1706
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 files, func.c containing a function which is called in main and main.c containing the main function. what is the difference when we link func.o with main.o to make a binary, with linking func.lib with main.o to make the binary, concerning security...
1
9910
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 defined as follows: extern unsigned mgl_numg, mgl_cur; extern float mgl_fact; extern long mgl_gen_fnt; extern short mgl_buf_fnt;
0
8375
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8707
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.