473,396 Members | 1,942 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,396 software developers and data experts.

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,INTERSECTATDIASTOLE}
twolinesolutioncases;

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::CSegment(void)
: m_pointlist(0)
, m_index(0)
, m_createdirection(true)
{
}

CSegment::~CSegment(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 INTERSECTATDIASTOLE;
}
....
return INTERSECT;

}

when I compile ,

Segment.cpp
Linking...
borderView.obj : error LNK2005: "enum TLSC twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
E:\border\0312\border\Debug\border.exe : fatal error LNK1169: one or more
multiply defined symbols found
Build log was saved at
"file://e:\border\0312\border\border\Debug\BuildLog.htm"
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 9807
* 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,INTERSECTATDIASTOLE}
twolinesolutioncases;
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 "precompiled 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,INTERSECTATDIASTOLE}
twolinesolutioncases;
You declare a global variable called "twolinesolutioncases" 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 twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
I think the compiler messages are pretty descriptive.

Regards,
Stuart
Mar 12 '07 #3

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

#include "MyPoint.h"

enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE}
twolinesolutioncases;
The line above declares an instance of TLSC called twolinesolutioncases.
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 twolinessolutionscases, 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 twolinesolutioncases;
and then in one, and only one of your compiliatin units (pick a .cpp) you
have
TLSC twolinesolutioncases;

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 twolinesolutioncases 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::CSegment(void)
: m_pointlist(0)
, m_index(0)
, m_createdirection(true)
{
}

CSegment::~CSegment(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 INTERSECTATDIASTOLE;
}
...
return INTERSECT;

}

when I compile ,

Segment.cpp
Linking...
borderView.obj : error LNK2005: "enum TLSC twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
Segment.obj : error LNK2005: "enum TLSC twolinesolutioncases"
(?twolinesolutioncases@@3W4TLSC@@A) already defined in border.obj
E:\border\0312\border\Debug\border.exe : fatal error LNK1169: one or more
multiply defined symbols found
Build log was saved at
"file://e:\border\0312\border\border\Debug\BuildLog.htm"
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.nowrote:
* fcvcnet:
enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE}
twolinesolutioncases;

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.nowrote:
>* fcvcnet:
>>enum TLSC {PARALLEL, INTERSECT, COINSIDE,INTERSECTATDIASTOLE}
twolinesolutioncases;
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
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 &)"...
3
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...
1
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. ...
1
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:...
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...
9
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...
1
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...
2
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......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.