By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,892 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,892 IT Pros & Developers. It's quick & easy.

LNK2005 error

P: n/a
Hi all,

I have this config.h file which has all the declarations for the vars
being used in the application. There are no compilation errors but link
errors for all the vars declared in this "iof_config.h" file.

//************************************************** **
//FILE : iof_library.h
//************************************************** **

#ifndef IOF_CONFIG_H
#define IOF_CONFIG_H 1

#include "iof_library.h"
// my own library for open, read and write to the queue,
// write to producer queue and read to consumer queue
#include "C_Q_Iterator_FIFO.h" // Q Iterators
#include "C_Q_Iterator_LastProduce.h"
#include "GeneralUtilities.h"
//************************************************** *************/
// This data comes from the XML file
//Array of all the producers
// Where:
// Producer 0 = Altitude
// Producer 1 = Airspeed
// Producer 2 = Pressure
// Producer 3 = Temperature
//************************************************** *************/
const int Produced_Items =4;
//************************************************** *************/
// Array of all the consumers
// Where:
// Consumer 0 = Knots, FIFO read
// Consumer 1 = Degree Celcius, Last Produced read //Always reads the
last value i.e.from the tail
// Consumer 2 = Feet, FIFO read
// Consumer 3 = psi, LastProduced read
//************************************************** *************/
const int Consumed_Items =4;

///************************************************** ******
// C_Queue instantions for the Producers
//************************************************** ******

//For Produced Item 1
C_Queue<Queue_Element> altitude(9, "Altitude");

//For Produced Item 2
C_Queue<Queue_Element> airspeed(5, "Airspeed");

//For Produced Item 3
C_Queue<Queue_Element> pressure(12, "Pressure");

//For Produced Item 4
C_Queue<Queue_Element> temperature(3, "Temperature");

//************************************************** ******
// C_Q_Iterator instantions for the Consumers
//************************************************** ******

//Consumed Item 1
C_Q_Iterator_FIFO<Queue_Element> altitude_iterator(&altitude, "Feet");

//Consumed Item 2
C_Q_Iterator_FIFO<Queue_Element> airspeed_iterator(&airspeed,"Knots");

//Consumed Item 3
C_Q_Iterator_LastProduce<Queue_Element>
pressure_iterator(&pressure,"PSI");

//Consumed Item 4
C_Q_Iterator_LastProduce<Queue_Element>
temperature_iterator(&temperature,"Degrees");
//************************************************** *************/
//Producer and Consumer Arrays
//************************************************** *************/
C_Queue<Queue_Element>* Producer[Produced_Items];
C_Q_Iterator<Queue_Element>* Consumer[Consumed_Items];

//************************************************** *************/
// Arrays for holding the unused indices in Producer and Consumer
arrays
// There can be max Produced(Consumed)_Items number of unused indices.
//************************************************** *************/
int empty_producer_indices[Produced_Items];
int empty_consumer_indices[Consumed_Items];

#endif

I am unable to understand that even though the file is inclusion
protected and there are only declarations why is this error.

Error message:

iof_library.obj : error LNK2005: "void __cdecl populate(void)"
(?populate@@YAXXZ) already defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Queue<struct Queue_Element> *
* Producer" (?Producer@@3PAPAV?$C_Queue@UQueue_Element@@@@A) already
defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Queue<struct Queue_Element>
pressure" (?pressure@@3V?$C_Queue@UQueue_Element@@@@A) already defined
in AppFile.obj
iof_library.obj : error LNK2005: "class C_Queue<struct Queue_Element>
temperature" (?temperature@@3V?$C_Queue@UQueue_Element@@@@A) already
defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Q_Iterator<struct
Queue_Element> * * Consumer"
(?Consumer@@3PAPAV?$C_Q_Iterator@UQueue_Element@@@ @A) already defined
in AppFile.obj
iof_library.obj : error LNK2005: "int * empty_producer_indices"
(?empty_producer_indices@@3PAHA) already defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Q_Iterator_FIFO<struct
Queue_Element> altitude_iterator"
(?altitude_iterator@@3V?$C_Q_Iterator_FIFO@UQueue_ Element@@@@A) already
defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Q_Iterator_LastProduce<struct
Queue_Element> temperature_iterator"
(?temperature_iterator@@3V?$C_Q_Iterator_LastProdu ce@UQueue_Element@@@@A)
already defined in AppFile.obj
iof_library.obj : error LNK2005: "int * empty_consumer_indices"
(?empty_consumer_indices@@3PAHA) already defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Queue<struct Queue_Element>
altitude" (?altitude@@3V?$C_Queue@UQueue_Element@@@@A) already defined
in AppFile.obj
iof_library.obj : error LNK2005: "class C_Queue<struct Queue_Element>
airspeed" (?airspeed@@3V?$C_Queue@UQueue_Element@@@@A) already defined
in AppFile.obj
iof_library.obj : error LNK2005: "class C_Q_Iterator_FIFO<struct
Queue_Element> airspeed_iterator"
(?airspeed_iterator@@3V?$C_Q_Iterator_FIFO@UQueue_ Element@@@@A) already
defined in AppFile.obj
iof_library.obj : error LNK2005: "class C_Q_Iterator_LastProduce<struct
Queue_Element> pressure_iterator"
(?pressure_iterator@@3V?$C_Q_Iterator_LastProduce@ UQueue_Element@@@@A)
already defined in AppFile.obj
The file App.obj just incudes iof_library.h. The vars declared in this
iof_library.h are not declared anywhere else. And only the vars in this
file are causing this link error.

Am I missing something here?

I am using MVisual Studio 6.

Thanks in Advance.

Jun 15 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11*********************@u72g2000cwu.googlegroups. com>,
"Taran" <ta************@gmail.com> wrote:
I am unable to understand that even though the file is inclusion
protected and there are only declarations why is this error.

Error message:

iof_library.obj : error LNK2005: "void __cdecl populate(void)"
(?populate@@YAXXZ) already defined in AppFile.obj
You aren't showing all the code. "populate()" isn't even *in* the header
you posted.

The simple answer is, contrary to your assertion, there are not "only
declarations" in one or more of your header files.

The header you posted has several definitions in it for example.
C_Queue<Queue_Element>* Producer[Produced_Items];
C_Q_Iterator<Queue_Element>* Consumer[Consumed_Items];

int empty_producer_indices[Produced_Items];
int empty_consumer_indices[Consumed_Items];


All of the above are definitions and should not be in a header file that
is included in more than one source file.
Jun 15 '06 #2

P: n/a
Just before, the error lnk2005 like
" EdgeH3.obj : error LNK2005: "public: virtual void __thiscall
EdgeH3::set_order(unsigned int,enum IAGEnums::Order,bool)"
(?set_order@EdgeH3@@UAEXIW4Order@IAGEnums@@_N@Z) has defined in
BoundaryInfo.obj
Element.obj : error LNK2005: "public: virtual void __thiscall
EdgeH3::set_order(unsigned int,enum IAGEnums::Order,bool)"
(?set_order@EdgeH3@@UAEXIW4Order@IAGEnums@@_N@Z) has defined in
BoundaryInfo.obj ."
has encountered to me,, goole the webside, some useful suggestiones
have not break in my mide. So, we search codes, and then, we find that
the "inline" has been lost before defing the inline member functions(
EdgeH3::set_order(unsigned int,enum IAGEnums::Order,bool) ). at last,
my project can linked successfully after the lost " inline" words has
been added.
So, i think that maybe is the "inline" words lost before the inline
function in the header files.
Daniel T. wrote:
In article <11*********************@u72g2000cwu.googlegroups. com>,
"Taran" <ta************@gmail.com> wrote:
I am unable to understand that even though the file is inclusion
protected and there are only declarations why is this error.

Error message:

iof_library.obj : error LNK2005: "void __cdecl populate(void)"
(?populate@@YAXXZ) already defined in AppFile.obj


You aren't showing all the code. "populate()" isn't even *in* the header
you posted.

The simple answer is, contrary to your assertion, there are not "only
declarations" in one or more of your header files.

The header you posted has several definitions in it for example.
C_Queue<Queue_Element>* Producer[Produced_Items];
C_Q_Iterator<Queue_Element>* Consumer[Consumed_Items];

int empty_producer_indices[Produced_Items];
int empty_consumer_indices[Consumed_Items];


All of the above are definitions and should not be in a header file that
is included in more than one source file.


Jun 22 '06 #3

P: n/a
Renzr wrote:
Just before, the error lnk2005 like

Please don't top-post. See item 4 of the FAQ entry below:

<http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4>

Brian
Jun 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.