473,473 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Linker error multiple definitions

Hello,

I am recieving a multiple definition error from the linker when I try
to build a project I am working on. The message states that the
functions I defined within an external .c source file are already
defined in the main program .obj file. I declared the functions in
seperate header files and used the pre-processor conditional #ifndef
FILE_H to make sure each header is only included once. Each .c source
file includes the associated header as does the main .c file which
calls the functions. I know I have done this before without any
problems, but am I missing a step? Thanks for any help.
Nov 13 '05 #1
4 30415
an***********@ca.com (Andrew) wrote:
I am recieving a multiple definition error from the linker when I try
to build a project I am working on. The message states that the
functions I defined within an external .c source file are already
defined in the main program .obj file. I declared the functions in
seperate header files and used the pre-processor conditional #ifndef
FILE_H to make sure each header is only included once.
Only once in each .c file you #include it in, not only once per project.
Each .c source
file includes the associated header as does the main .c file which
calls the functions.


Don't _define_ objects in headers. _Declare_ objects in headers, then
define them - once - in an appropriate .c file.

Richard
Nov 13 '05 #2
Andrew wrote:
I am recieving a multiple definition error from the linker when I try
to build a project I am working on. (...)


Maybe we can help if you show us the exact error message(s) for one
symbol, as well as the .h source snippet and the .c file snippet which
declares the corresponding symbol.

--
Hallvard
Nov 13 '05 #3
Andrew wrote:
I am receiving a multiple definition error from the linker
when I try to build a project I am working on.
The message states that the functions I that defined
within an external .c source file are already defined
in the main program .obj file.
I declared the functions in separate header files
Are you sure that you didn't actually *define* the function
in the header files?
and used the pre-processor conditional #ifndef FILE_H
to make sure each header is only included once.
But your compiler isn't complaining about multiple *declarations*.
It is complaining about multiple *definitions*.
You can *declare* a function multiple times
but it should only be *defined* once.
Each .c source file includes the associated header as does the
main .c file which calls the functions. I know I have done this before
without any problems, but am I missing a step? Thanks for any help.

Nov 13 '05 #4
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message news:<3F**************@jpl.nasa.gov>...
Andrew wrote:
I am receiving a multiple definition error from the linker
when I try to build a project I am working on.
The message states that the functions I that defined
within an external .c source file are already defined
in the main program .obj file.
I declared the functions in separate header files


Are you sure that you didn't actually *define* the function
in the header files?
and used the pre-processor conditional #ifndef FILE_H
to make sure each header is only included once.


But your compiler isn't complaining about multiple *declarations*.
It is complaining about multiple *definitions*.
You can *declare* a function multiple times
but it should only be *defined* once.
Each .c source file includes the associated header as does the
main .c file which calls the functions. I know I have done this before
without any problems, but am I missing a step? Thanks for any help.


Thanks everyone. I think I found the problem. It was not actually the
functions that the errors were citing, but some arrays which I
declared and initiliazed within the header files such as

int riff1[11] = {7,9,10,12,14,12,7,9,5,7,5};

Now that I moved these arrays to the .c source file from the header
everything is working again. I guess I was re-initializing or
re-defining these arrays each time I included the headers. Thanks
again
Nov 13 '05 #5

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

Similar topics

8
by: Generic Usenet Account | last post by:
Our C++ program was linked with some legacy C functions. We had used the extern "C" declaration, and everything was working fine. Then someone thought that it would be better to have a consistent...
0
by: Tom McDermott | last post by:
I am having linker errors : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types This code linked sucessfully in C++.NET 2002, but does...
3
by: Felix Kater | last post by:
Hi, I've got the header myheader.h: #ifndef MY_HEADER #define MY_HEADER const int my_const_int = 99; /* ... */ #endif
4
by: pavan734 | last post by:
Hello I have one .h file which I have includeded completely under #ifndef followed by #define guards. I have the member function definitions in the same .h file only. Still Iam getting linker...
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 ----------------------- ...
2
by: Markus Dehmann | last post by:
What to do if an external library is header-files-only (but you have to use it), and you get lots of linker errors? You will necessarily get linker errors "multiple definition of ..." if you try...
5
by: VanKha | last post by:
Hi everyone , I've just read a book on Computer Systems.(Computer Systems:A programmer's perspective ) . On the part of "Linking" , the author talks about strong/weak symbol and as an example for...
3
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
11
by: Tim H | last post by:
The following program compiles just fine in C, but not in C++. Can anyone explain why? I have a chunk of code that defines stuff like this in headers (without the extern) that I can not easily...
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
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,...
1
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.