473,395 Members | 1,442 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,395 software developers and data experts.

C linker error

I have this situation

file1.h
{ define struct ... B;
}

file2.c
{ include file1.h
make use of B}

file2.c
{ include file1.h
make use of B .. }

It compiles ok however when it tries to link, It gives the famous error
Struct B : warning, multiply defined symbol

Can anyone help on what i should be looking for ?
I don't see anything wrong in the code ..

Thanks
Nov 14 '05 #1
4 5087
In article <Xg*********************@weber.videotron.net>,
franco ziade <fz****@videotron.ca> wrote:
:I have this situation

:file1.h
:{ define struct ... B;
:}

:file2.c
:{ include file1.h
:make use of B}

:file2.c
:{ include file1.h
:make use of B .. }

:It compiles ok however when it tries to link, It gives the famous error
:Struct B : warning, multiply defined symbol

If you are linking file2.c in twice to the same executable, it is not
surprising that you are getting duplicate symbols.

I will presume here that you mean file1.c in the first inclusion,
rather than file2.c.
:Can anyone help on what i should be looking for ?
:I don't see anything wrong in the code ..

If file1.h defines storage for B, rather than just declaring a type
for B, then when you include it in file1.c you are defining that storage
as being part of file1.o, and when you include file1.h in file2.c
you are defining that storage as being part of file2.o. Link the two
together and of course your symbol is multiply defined.

In file1.h you should only declare the type of B, and possibly have
an 'extern' reference to it. Then in -one- place, define it's storage.
--
Usenet is one of those "Good News/Bad News" comedy routines.
Nov 14 '05 #2
I am sorry .. the third file is file3.c
Now it is corrected below

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:cv**********@canopus.cc.umanitoba.ca...
In article <Xg*********************@weber.videotron.net>,
franco ziade <fz****@videotron.ca> wrote:
:I have this situation

:file1.h
:{ define struct ... B;
:}

:file2.c
:{ include file1.h
:make use of B}

:file3.c
:{ include file1.h
:make use of B .. }

:It compiles ok however when it tries to link, It gives the famous error
:Struct B : warning, multiply defined symbol

If you are linking file2.c in twice to the same executable, it is not
surprising that you are getting duplicate symbols.

I will presume here that you mean file1.c in the first inclusion,
rather than file2.c.
:Can anyone help on what i should be looking for ?
:I don't see anything wrong in the code ..

If file1.h defines storage for B, rather than just declaring a type
for B, then when you include it in file1.c you are defining that storage
as being part of file1.o, and when you include file1.h in file2.c
you are defining that storage as being part of file2.o. Link the two
together and of course your symbol is multiply defined.

In file1.h you should only declare the type of B, and possibly have
an 'extern' reference to it. Then in -one- place, define it's storage.
--
Usenet is one of those "Good News/Bad News" comedy routines.

Nov 14 '05 #3
On Wed, 23 Feb 2005 19:31:03 -0500, "franco ziade"
<fz****@videotron.ca> wrote in comp.lang.c:
I have this situation

file1.h
{ define struct ... B;
}

file2.c
{ include file1.h
make use of B}

file2.c
{ include file1.h
make use of B .. }

It compiles ok however when it tries to link, It gives the famous error
Struct B : warning, multiply defined symbol

Can anyone help on what i should be looking for ?
I don't see anything wrong in the code ..

Thanks


Show the real code from file1.h. All references to the structure
type. Nobody can tell for sure what your mistake is from the non C
text that you posted.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #4
franco ziade wrote:
I am sorry .. the third file is file3.c
Now it is corrected below


But the explanation still is the same:
If you are _defining_ storage in your header-file and then including
this headerfile into two different c-files, you are actually defining the
same stuff two times, once in file2.c and once in file3.c
(include is a textual include, so everything in file1.h becomes part of
file2.c AND file3.c)
In file1.h you should only declare the type of B, and possibly have
an 'extern' reference to it. Then in -one- place, define it's storage.


That's exactly what you have to do to oevrcome the error.

HTH
Jogi

--
The particular mistake will not be repeated. There are plenty of
mistakes left that have not yet been used.**********A.*Tanenbaum**
Jo*****@kuenstner.de
Nov 14 '05 #5

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

Similar topics

12
by: Baloff | last post by:
Hello I have this linker error which makes me think that the definition file is not being seen by the linker, this code is taken from "Thinking in C++, 2nd Edition, Volume 1, Annotated Solutions...
1
by: Laszlo | last post by:
Hi all, As a novice I installed PostgreSQL 7.2.1 on Win32 and works, Borland C++Builder Enterprise Suite 5.0 (build 12.34) what works too. I decided to combine these two programs and develop a...
5
by: Pradnyesh Rane | last post by:
Hi, I am encountering the following linker error on VC7. LINK : fatal error LNK1171: unable to load ole32.dll This error is only encountered for the "Debug" configuration. The project...
3
by: Steve Baer | last post by:
I recently read your whitepaper under the "extremely long link times" post and have a question that I was hoping you could answer. My question is based on the following paragraph: Directives...
9
by: Peter Oliphant | last post by:
For some reson my code is generating a LNK1215 error, which 'suggests' I re-install VS C++. So I did. which did NOT solve the problem. The weid part is it seems to be caused by my one CPP file, but...
3
by: Chucker | last post by:
Hi Folks, I got a Wrapper Dll around a native C++ static library. In .NET 1.1 this worked fine. When moving to .NET 2.0 I get a couple of unresolved externals / linker errors: Error 16 error...
1
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits...
4
by: yOtA | last post by:
I get this Linker Errors while compiling my program: Error: Unresolved external 'vminit()' referenced from C:\TESTE\TESTE.OBJ Error: Unresolved external 'vmalloc(void *, int, unsigned int,...
1
by: Deepath G | last post by:
This is deepath.. I am getting some linker error when i am trying to connect Websphere MQ using Borland C++ Builder 2006 using imqi.hpp on windows. Error Message ----------------------- ...
3
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.