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

error LNK2005:already defined

P: n/a
Hi ,

I am getting the following LINK 2005 error when I tried to build my
project in vc++7.1.
I am doing the build process in win32release mode.

I have searched google on this but whatever I found was related to
standard dll's and lib's.

Here in my case it is not a standard lib.It is generated by a different
project in another workspace.

-----------------------------------------------------------------------------------------------------------------------------------
ghjkl.lib(ghjkl.dll) : error LNK2005: "public: int __thiscall
OSF_Task<class OSF_Thread_Mutex,class
OSF_Condition_Thread_Mutex>::getq(class OSF_Message_Block * &,class
OSF_Time_Value *)"
(?getq@?$OSF_Task@VOSF_Thread_Mutex@@VOSF_Conditio n_Thread_Mutex@@@@QAEHAAPAVOSF_Message_Block@@PAVO SF_Time_Value@@@Z)
already defined in abc.obj
-------------------------------------------------------------------------------------------------------------------------------------

The function getq(class OSF_Message_Block * &,class OSF_Time_Value *)
is not defined in abc.cpp but it is declared and defined in another
header file asd.h.

I am putting the relevant code below.

***asd.h
----------------------------------------------------------------------------------------------------------------------------------
class ghj{
typedef STL_Message_Queue<OSF_Recursive_Thread_Mutex, OSF_Manual_Event>
MessageQueue;

int getq(OSF_Message_Block*& mb, OSF_Time_Value* tv=0)
{
return mq_->dequeue_head(mb,tv);
}
private:
MessageQueue* mq_;

}
-------------------------------------------------------------------------------------------------------------------------------------
Any help is appreciated.

Thanks in advance

Best Regards,
Rohini Chandra

May 10 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Rohini" <ro************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hi ,

I am getting the following LINK 2005 error when I tried to build my
project in vc++7.1.
I am doing the build process in win32release mode.

I have searched google on this but whatever I found was related to
standard dll's and lib's.

Here in my case it is not a standard lib.It is generated by a different
project in another workspace.

-----------------------------------------------------------------------------------------------------------------------------------
ghjkl.lib(ghjkl.dll) : error LNK2005: "public: int __thiscall
OSF_Task<class OSF_Thread_Mutex,class
OSF_Condition_Thread_Mutex>::getq(class OSF_Message_Block * &,class
OSF_Time_Value *)"
(?getq@?$OSF_Task@VOSF_Thread_Mutex@@VOSF_Conditio n_Thread_Mutex@@@@QAEHAAPAVOSF_Message_Block@@PAVO SF_Time_Value@@@Z)
already defined in abc.obj
-------------------------------------------------------------------------------------------------------------------------------------

The function getq(class OSF_Message_Block * &,class OSF_Time_Value *)
is not defined in abc.cpp but it is declared and defined in another
header file asd.h.

I am putting the relevant code below.

***asd.h
----------------------------------------------------------------------------------------------------------------------------------
class ghj{
typedef STL_Message_Queue<OSF_Recursive_Thread_Mutex, OSF_Manual_Event>
MessageQueue;

int getq(OSF_Message_Block*& mb, OSF_Time_Value* tv=0)
{
return mq_->dequeue_head(mb,tv);
}
private:
MessageQueue* mq_;

}
-------------------------------------------------------------------------------------------------------------------------------------
Any help is appreciated.


This isn't really the code that causes that error, is it? The error refers
to a template class named OSF_Task<T1,T2> where here you're showing a class
ghj that's not a template.

In the real code, is the definition of getq outside the body of the class?

e.g.

int ghj::getq(...)

If so, you need to add the inline keyword to that out of line definition, or
move it to a .cpp file instead of the .h file.

-cd
May 10 '06 #2

P: n/a
Hi Carl,

Thanks for the information.
The definition of getq is inside the body of the class.
I have tried to place the definition in a.cpp file and compile but it
did not work.

Here is some more information which can help you analyse my
problem.There are two .h files where the function is declared and
defined one is abc.h and the other efg.h
================================================== ================================================== =====================

abc.h
==================
typedef OSF_Task<OSF_MT_SYNCH> Task;

class Task: public OSF_Event_Handler
{
public:
int getq(OSF_Message_Block*& mb, OSF_Time_Value* tv=0)
{
return mq_->dequeue_head(mb,tv);
}
}
=========abc.h

efg.h
========
template <OSF_SYNCH_DECL>
class OSF_Task : public OSF_Task_Base
{
Public:
int getq (OSF_Message_Block *&mb, OSF_Time_Value *timeout = 0);
}
template <OSF_SYNCH_DECL>
OSF_INLINE int
OSF_Task<OSF_SYNCH_USE>::getq (OSF_Message_Block *&mb, OSF_Time_Value
*tv)
{
return this->msg_queue_->dequeue_head (mb, tv);
}
=========efg.h

efg.h is included in abc.h

class OSF_Task_Base,class Task inherit from OSF_Event_Handler

# define OSF_MT_SYNCH OSF_Thread_Mutex, OSF_Condition_Thread_Mutex

# define OSF_SYNCH_DECL class _OSF_SYNCH

# define OSF_SYNCH_USE _OSF_SYNCH
================================================== ================================================== =====================

Please help me resolve this problem.
Thanks once again.
Carl Daniel [VC++ MVP] wrote:
"Rohini" <ro************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hi ,

I am getting the following LINK 2005 error when I tried to build my
project in vc++7.1.
I am doing the build process in win32release mode.

I have searched google on this but whatever I found was related to
standard dll's and lib's.

Here in my case it is not a standard lib.It is generated by a different
project in another workspace.

-----------------------------------------------------------------------------------------------------------------------------------
ghjkl.lib(ghjkl.dll) : error LNK2005: "public: int __thiscall
OSF_Task<class OSF_Thread_Mutex,class
OSF_Condition_Thread_Mutex>::getq(class OSF_Message_Block * &,class
OSF_Time_Value *)"
(?getq@?$OSF_Task@VOSF_Thread_Mutex@@VOSF_Conditio n_Thread_Mutex@@@@QAEHAAPAVOSF_Message_Block@@PAVO SF_Time_Value@@@Z)
already defined in abc.obj
-------------------------------------------------------------------------------------------------------------------------------------

The function getq(class OSF_Message_Block * &,class OSF_Time_Value *)
is not defined in abc.cpp but it is declared and defined in another
header file asd.h.

I am putting the relevant code below.

***asd.h
----------------------------------------------------------------------------------------------------------------------------------
class ghj{
typedef STL_Message_Queue<OSF_Recursive_Thread_Mutex, OSF_Manual_Event>
MessageQueue;

int getq(OSF_Message_Block*& mb, OSF_Time_Value* tv=0)
{
return mq_->dequeue_head(mb,tv);
}
private:
MessageQueue* mq_;

}
-------------------------------------------------------------------------------------------------------------------------------------
Any help is appreciated.


This isn't really the code that causes that error, is it? The error refers
to a template class named OSF_Task<T1,T2> where here you're showing a class
ghj that's not a template.

In the real code, is the definition of getq outside the body of the class?

e.g.

int ghj::getq(...)

If so, you need to add the inline keyword to that out of line definition, or
move it to a .cpp file instead of the .h file.

-cd


May 10 '06 #3

P: n/a
Hi Carl,
I am very sorry for misguiding you.
There is if else condition which I did not provide in my previous
reply.

abc.h
==================
#ifdef USE_OWN_TASK

class Task: public OSF_Event_Handler
{
public:
int getq(OSF_Message_Block*& mb, OSF_Time_Value* tv=0)
{
return mq_->dequeue_head(mb,tv);
}
}
#else
typedef OSF_Task<OSF_MT_SYNCH> Task;
=========abc.h

May 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.