473,405 Members | 2,404 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,405 software developers and data experts.

error LNK2005:already defined

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
3 1690
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: tshad | last post by:
Here is the DropDown: <asp:DropDownList ID="ScreenTest" runat="server" /> Here is the code: ScreenTest.DataSource=objCmd.ExecuteReader ScreenTest.DataValueField="ScreenTemplateMasterID"...
0
by: mcskf | last post by:
Hi, We develop a web based app in VB.Net 1.1. We use an conrol class for holding user's variables. The control process is created when the session created. In the control class we have many...
0
by: Taran | last post by:
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...
2
by: le0 | last post by:
guys, this is my first time to deploy website to the server, but every time i access the page this error always appears. ...
6
by: fcvcnet | last post by:
Hi all, I defined a class, as fellows: // Segment.h #pragma once #include "MyPoint.h" enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE} twolinesolutioncases;
2
by: curious2007 | last post by:
During the linking I get the following: 1>Linking... 1>main.obj : error LNK2005: "double __cdecl sigma(class curious2007::pair<double,double> const &)" (?sigma@@YANABV?$pair@NN@curious2007@@@Z)...
1
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include...
3
by: FeelLikeANut | last post by:
I have the code below. First there is a transaction where I select data. I wrapped it in an explicit transaction because in my real program I run a couple different selects. Nevertheless, the...
9
by: Brian Dude | last post by:
Hello, I'm really at a loss as to what's going wrong with my code. I have it posted below. How it appears is how I had it originally. I've deleted all error-checking for simplicity: #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
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,...
0
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...

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.