LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-22-2006, 04:06 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
Multiple definitions... what should I be looking for??


With the eradication of the problem in my previous thread, I ventured further with my little program...

... now when I make my program I get the following error:

george@George:~/George Lair/030506$ make
g++ -c main.cpp
g++ -c fight.cpp
g++ -c gSDL.cpp
g++ -g main.o fight.o gSDL.o -Wall `sdl-config --cflags --libs` -lSDL -o test031206
fight.o:\(.bss+0x8): multiple definition of `yloc'
main.o:\(.bss+0x0): first defined here
fight.o:\(.bss+0xc): multiple definition of `xloc'
main.o:\(.bss+0x4): first defined here
fight.o:\(.bss+0x10): multiple definition of `screen'
main.o:\(.bss+0x8): first defined here
gSDL.o:\(.bss+0x0): multiple definition of `yloc'
main.o:\(.bss+0x0): first defined here
gSDL.o:\(.bss+0x4): multiple definition of `xloc'
main.o:\(.bss+0x4): first defined here
gSDL.o:\(.bss+0x8): multiple definition of `screen'
main.o:\(.bss+0x8): first defined here
collect2: ld returned 1 exit status
make: *** [test031206] Error 1
george@George:~/George Lair/030506$

At first I thought it was being confused with some other defintion of x and y that were arguements to functions ( ex: int move_left(int x, int y)). But I seem to have crossed that out for now.(though I still would like to know if I would have conflicts with same variables but within different locations.. such as one int x being global [in the headerfile.h] and the other being in a function arguement parameter. Any answer to this question would be greatly appreciated) Anyways, what exactly should I be looking for... again I do not want a direct answer if at all possible, but just a hint in the right direction. I have uploaded the files in pntbalg.shackspace.com/GeorgeLair/032206. Thank you in advance.

PS: Sorry for lack of documentation and the absence of helpfull comments... once I have 10 minutes to burn I'll spend it commenting in the code, maybe add a readme.
 
Old 03-22-2006, 06:17 PM   #2
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
I think this error describes very well what it is: You have multiple definitions of those variables. I don't know your code, but let's take the variable "yloc"; I guess you defined it in "fight.h" (or so) at global scope? If this is true, then I think further, that you included this file ("fight.h")in "fight.cpp" as well as in "main.cpp" ==> multiple definitions!

And the other thing: You won't get any conflicts, if you use the same name for variables in different/nested scopes. If you do so, then the most inner variable will be used.
 
Old 03-22-2006, 10:09 PM   #3
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
It's strange how it says multiple def in fight.o when it is never even called. Only in headerfiles.h does it declare xloc and yloc globaly. Here is part of my headerfiles.h

#ifndef HEADERFILES_H

#define HEADERFILES_H



#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <SDL/SDL.h>

SDL_Surface *screen;


int xloc, yloc;
void fightque();
int fight();
int fightstart(int who, int player, int mob);
void display_bmp(char *file_name, int x2, int y2);



using namespace std;

#endif

Is there anything not usualy done in the ^above^ code?
 
Old 03-23-2006, 05:27 AM   #4
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
Ok, I had a little look at your code and it is like I guessed in my first post: You have defined those variables globally in "headerfiles.h" and included this file in "main.cpp" as well as in other files like "fight.cpp". You have to know, that the "include"-directive really includes the whole given file, it's just like you would copy the file's content at that position. With that in mind your error should be clear, or isn't it? -You have included the hederfile to "main.cpp" ==> variables are defined there; but you also included it i.e. in "fight.cpp" ==> variables are also defined there ==> multiple definitions. You said you don't want a direct solution, so I won't give it to you, but I hope this helps.

Last edited by Flesym; 03-23-2006 at 05:31 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Type Definitions ChemicalBurn Programming 2 02-22-2005 05:03 AM
Multiple Definitions Error in KDevelop lasindi Programming 2 08-03-2004 03:20 AM
Alias Definitions collegenate Linux - Newbie 1 02-09-2003 02:06 AM
Definitions..? mikeyt_333 Linux - General 4 02-06-2002 01:45 PM
Linux Definitions newbietolinux Linux - Newbie 6 01-20-2002 07:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration