473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

faq error LNK2005: ...already defined


Hi all,
I defined a class, as fellows:
// Segment.h
#pragma once

#include "MyPoint.h"

enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesolution cases;

class CSegment
{
public:
CSegment(void);
void Clear();
public:
~CSegment(void) ;
private:
....
....
....
friend TLSC InterSect(const CSegment &sgmt1, const CSegment &sgmt2,
CMyPoint &intersectpoint );
....
};

And at the file segment.cpp below I defined a function to be a global
function
// Segment.cpp
#include "StdAfx.h"
#include "Segment.h"

CSegment::CSegm ent(void)
: m_pointlist(0)
, m_index(0)
, m_createdirecti on(true)
{
}

CSegment::~CSeg ment(void)
{
}
....

TLSC InterSect(const CSegment &sgmt1, const CSegment &sgmt2, CMyPoint
&intersectpoint )
{
double ua,ub;//ub can be delete
double a,b,c;
....
if (0==c)
{
if (a==b==0)
{
return COINSIDE;
}
return PARALLEL;
}
....
if ( ua < 0 || ua 1 || ub < 0 || ub 1)
{
return INTERSECTATDIAS TOLE;
}
....
return INTERSECT;

}

when I compile ,

Segment.cpp
Linking...
borderView.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
E:\border\0312\ border\Debug\bo rder.exe : fatal error LNK1169: one or more
multiply defined symbols found
Build log was saved at
"file://e:\border\0312\ border\border\D ebug\BuildLog.h tm"
border - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How to solove this errors?
Thanks.
Mar 12 '07 #1
6 9834
* fcvcnet:
Hi all,
I defined a class, as fellows:
// Segment.h
#pragma once
This effect of this #pragma, if any, depends on the compiler.

#include "MyPoint.h"

enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesolution cases;
Java'ism: don't use all uppercase names except for macros.
class CSegment
{
public:
CSegment(void);
void Clear();
public:
~CSegment(void) ;
private:
...
...
...
friend TLSC InterSect(const CSegment &sgmt1, const CSegment &sgmt2,
CMyPoint &intersectpoint );
...
};

And at the file segment.cpp below I defined a function to be a global
function
// Segment.cpp
#include "StdAfx.h"
This is not a standard header. In addition it indicates you're using a
feature of Visual C++ called "precompile d headers", where the compiler
will not abide by standard C++ rules. Nothing more can be said until
you turn off that feature and remove this header.

Post a small, standard C++ program that exhibits the problem, if it's
still there when you remove the compiler-specific stuff.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 12 '07 #2
fcvcnet wrote:
Hi all,
I defined a class, as fellows:
// Segment.h
#pragma once

#include "MyPoint.h"

enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesolution cases;
You declare a global variable called "twolinesolutio ncases" of type TLSC
here. That is not a good thing to do in a header file. I guess you
forgot to make this a typedef.
>
class CSegment
[snipped rest of code]
when I compile ,

Segment.cpp
Linking...
borderView.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
I think the compiler messages are pretty descriptive.

Regards,
Stuart
Mar 12 '07 #3

"fcvcnet" <fc*****@163.co mwrote in message
news:et******** **@news.cn99.co m...
>
Hi all,
I defined a class, as fellows:
// Segment.h
#pragma once

#include "MyPoint.h"

enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesolution cases;
The line above declares an instance of TLSC called twolinesolution cases.
Any seperation compilation unit (.obj) which has a .cpp which includes this
header will have an instance. So when you go to link, the linker says, hey,
wait, you got a bunch of twolinessolutio nscases, which one am I supped to
use?

There are a few solutions to this depending on what you are trying to do.
One solutions is to make this

extern TLSC twolinesolution cases;
and then in one, and only one of your compiliatin units (pick a .cpp) you
have
TLSC twolinesolution cases;

so there is only one instance, and the extern says, it exists in one of the
compiliation units, find it linker.

That is, if you really need twolinesolution cases to be global. Do you?
class CSegment
{
public:
CSegment(void);
void Clear();
public:
~CSegment(void) ;
private:
...
...
...
friend TLSC InterSect(const CSegment &sgmt1, const CSegment &sgmt2,
CMyPoint &intersectpoint );
...
};

And at the file segment.cpp below I defined a function to be a global
function
// Segment.cpp
#include "StdAfx.h"
#include "Segment.h"

CSegment::CSegm ent(void)
: m_pointlist(0)
, m_index(0)
, m_createdirecti on(true)
{
}

CSegment::~CSeg ment(void)
{
}
...

TLSC InterSect(const CSegment &sgmt1, const CSegment &sgmt2, CMyPoint
&intersectpoint )
{
double ua,ub;//ub can be delete
double a,b,c;
...
if (0==c)
{
if (a==b==0)
{
return COINSIDE;
}
return PARALLEL;
}
...
if ( ua < 0 || ua 1 || ub < 0 || ub 1)
{
return INTERSECTATDIAS TOLE;
}
...
return INTERSECT;

}

when I compile ,

Segment.cpp
Linking...
borderView.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolution cases"
(?twolinesoluti oncases@@3W4TLS C@@A) already defined in border.obj
E:\border\0312\ border\Debug\bo rder.exe : fatal error LNK1169: one or more
multiply defined symbols found
Build log was saved at
"file://e:\border\0312\ border\border\D ebug\BuildLog.h tm"
border - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

How to solove this errors?
Thanks.

Mar 12 '07 #4
On Mar 13, 12:45 am, "Alf P. Steinbach" <a...@start.now rote:
* fcvcnet:
enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesolution cases;

Java'ism: don't use all uppercase names except for macros.
I was using this convention before Java even existed.. (and still do)

Why do you think using upper case for enumerated constants is bad?
Mar 13 '07 #5
* Old Wolf:
On Mar 13, 12:45 am, "Alf P. Steinbach" <a...@start.now rote:
>* fcvcnet:
>>enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERS ECTATDIASTOLE}
twolinesoluti oncases;
Java'ism: don't use all uppercase names except for macros.

I was using this convention before Java even existed.. (and still do)
For that matter, Dennis Ritchie also did. He also used all uppercase
for typedef'ed names. Very useful.[1]

Why do you think using upper case for enumerated constants is bad?
You mean, why is it bad.

It's bad because (1) it increases the chance of name collisions with
macros, and (2) because all caps is visually distracting.

Why it's a good idea to keep the macro "namespace" as separate as
possible: macros don't respect namespaces or scopes.

Notes:
[1] Nowadays many people are so insanely stupid, especially in the
country infamous for "Warning: the coffee is hot!", that it's dangerous
to use obvious irony lest one be misunderstood, so in the manner of CNN
stating that their story of wilful, bored robots on Mars was irony, here
goes: the statement about the usefulness of all caps was /irony/.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 13 '07 #6
Thanks you so much.
Mar 13 '07 #7

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

Similar topics

1
4042
by: arkam | last post by:
Hi, Here are my link errors : atlsd.lib(ATLComTime.obj) : error LNK2005: "public: __thiscall ATL::COleDateTime::COleDateTime(struct tagVARIANT const &)" (??0COleDateTime@ATL@@QAE@ABUtagVARIANT@@@Z) already defined in atlsd.lib(ATLComTime.obj) atlsd.lib(ATLComTime.obj) : error LNK2005: "public: void __thiscall ATL::COleDateTime::SetStatus(enum ATL::COleDateTime::DateTimeStatus)"
3
1710
by: Rohini | last post by:
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
1
7906
by: sethuganesh | last post by:
HI, i have ported vc++ 6.0 code to visual studio 2005. During batch build in debug mode i din't get any error.But if i build the same in release mode i am getting the following error. LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in atlmincrt.lib(atlinit.obj) LIBCMT.lib(tidtable.obj) : error LNK2005: __encoded_null already defined in atlmincrt.lib(atlinit.obj)
1
11984
nabh4u
by: nabh4u | last post by:
hi, i am getting a link error in my program which states that some variable which i declared in my header file is already defined in the object file. The error is like this: error LNK2005: "struct list * first" (?first@@3PAUmylist@@A) already defined in list.obj error LNK2005: "struct list * last" (?first@@3PAUmylist@@A) already defined in list.obj error LNK2005: "struct list * current" (?first@@3PAUmylist@@A) already defined in list.obj...
2
4245
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) already defined in Characteristics.obj 1>main.obj : error LNK2005: "double __cdecl sigma_linear(struct std::pair<double,double> const &)" (?sigma_linear@@YANABU?$pair@NN@std@@@Z) already defined in Characteristics.obj 1>main.obj : error LNK2005:...
1
5733
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 "RV2AJFRONT_NEW_private.h"
9
3214
by: dewi | last post by:
Dear All, I have several problem about VC++. I succeed to convert Simulink MATLAB to C code using Real-Time Workshop. I am trying to compile a C code using Visual C++ and found the error. Can anyone explain how to solve it? --------------------Configuration: PROJECT2 - Win32 Debug-------------------- Linking... RV2AJFRONT_NEW.obj : error LNK2005: _rtM_RV2AJFRONT_NEW already defined in RV2AJFRONT_NEW.obj RV2AJFRONT_NEW.obj : error...
1
2308
by: patelcm22 | last post by:
Hi, I am facing following errors while building my application. Error 4 fatal error LNK1169: one or more multiply defined symbols found C:\Documents and Settings\chirag.patel\Desktop\Game\GameTest\Debug\GameTest.exe 1 Error 2 error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) uafxcwd.lib Error 3 error LNK2005: "void * __cdecl operator new(unsigned int)"...
2
3246
by: randa zaghdan | last post by:
Hi I have a problem with my program in vc 2008 When I compile it, the following errors are listed. I try to resolve it but no hope Does any one can help me ? thanks . Linking... 1>tdrawAa.obj : error LNK2005: _main already defined in tclose.obj
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.