Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double defining in obj

Status
Not open for further replies.

Voker57

Programmer
Feb 2, 2003
22
RU
I'm defining global variables zz and nn in Plot.h, modyfying them in plot.cpp and using in The PlotView.cpp. And when compiling it shows that:
>> The PlotView.obj : error LNK2005: "int nn" (?nn@@3HA)
>> already defined in Plot.obj
>> The PlotView.obj : error LNK2005: "int zz" (?zz@@3HA)
>> already defined in Plot.obj
>> Debug/The Plot.exe : fatal error LNK1169: one or more
>> multiply defined symbols found
What it means? I haven't defined them anywhere else!

I'm from Russia :)
 
Your plot.h should look :
#ifndef __PLOT_H__
#define __PLOT_H__

// declarations

#endif

-obislavu-
 
Heh...no results. If you need more info, just ask.

I'm from Russia :)
 
Does plotview include the plot.h file ?

Have you tried to rebuild your project ? (Clears out old references sometimes)
 
My guess is you have

Code:
int nn = 0;
In the plot.h file

What you should have in the plot.h file is
Code:
extern int nn;

And ONLY in plot.cpp
Code:
int nn = 0;

--
 
I believe if you are from Russia it does not mean yet what you are dummie. Moveover, in Russia are many very good programmers.

Ion Filipski
1c.bmp
 
>> Does plotview include the plot.h file ?
>> Have you tried to rebuild your project ? (Clears out old
>> references sometimes)
Yes to both.
>> My guess is you have
>> int nn = 0;
>> In the plot.h file
>> What you should have in the plot.h file is
>> extern int nn;
>> And ONLY in plot.cpp
>> int nn = 0;
It shows new errors:
>> The PlotView.obj : error LNK2001: unresolved external
>> symbol "int zz" (?zz@@3HA)
>> The PlotView.obj : error LNK2001: unresolved external
>> symbol "int nn" (?nn@@3HA)

2 IonFilipski: I meant not it... but i too think this is a dumb underwriting.


I'm from Russia :)
 
It shows new errors:
>> The PlotView.obj : error LNK2001: unresolved external

Means you're trying to make plotview.cpp a program in it's own right.
You need to compile both Plot.cpp and PlotView.cpp, then link BOTH object files to make it work.


--
 
>> Means you're trying to make plotview.cpp a program in it's
>> own right.
>> You need to compile both Plot.cpp and PlotView.cpp, then link
>> BOTH object files to make it work.
I've done it. No result. :-(((
 
Ok, lets put togeevr everithing is said there:

//begin of plot.h
#ifndef __PLOT_H__
#define __PLOT_H__

extern int nn;
extern int zz;


// ... other declarations

#endif
//end of plot.h

//begin of plot.cpp
#include "plot.h"
//initialization in only one file of the project
int nn = 1223;
int zz;
..........
//end of plot.cpp


//everything else.cpp:
#include "plot.h"

//use zz and nn but don't declare it again:
zz = 654
nn = zz;
int y = nn;

>Voker57
(I'm from ex URSS too:)

Ion Filipski
1c.bmp
 
......no.....result......:-(((
>> (I'm from ex URSS too:)
It's obvious from your nick. Hey, Slavyane!


Hi there!
 
Follow some rules:
1. Never!!! #include files with extension .c and .cpp
2. Any declarations of some global variable put in a single place in a .cpp or .c file!!!!
3. For any other declarations use keyword extern.

So,
look at each symbol what repeats in your project. Find it in all places where you can find it and follow 1, 2, 3.

Ion Filipski
1c.bmp
 
May be my windows are buggy, or something else...
...I follow them! :-(

Hi there!
 
It's just a complete gemorroy. Can anyone watch my codes? I did it up, back and forth!

Hi there!
 
Ok, contct me directly, for example on ICQ. My contacts are in my details.

Ion Filipski
1c.bmp
 
maybe you send too many files? my address sure works, you are not the first person who contacts me. Send only source files in a zip archive not bigger than 50kb

Ion Filipski
1c.bmp
 
Now it works. Maybe it was an error.

Hi there!
 
It sents me this letter back:
>> This message was created automatically by mail delivery >> software.

>> A message that you sent could not be delivered to one or >> more of its
>> recipients. This is a permanent error. The following
>> address(es) failed:

>> filipski@excite.com
>> SMTP error from remote mailer after RCPT
>> TO:<filipski@excite.com>:
>> host xmxpita.excite.com [208.45.133.107]: 554
>> <voker57@inbox.ru>:
>> Sender address rejected: Sender address rejected:
>> Access denied Error: WS-10



Hi there!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top