Compiling in windows

I am making a scrolling shooter game(SSG) is C++ with SDL library , I use the following command to compile in linux:
 
g++ -o scrolling_shooter_game ammo.cpp enemy_ammo.cpp enemy.cpp shooter.cpp enemy_maker.cpp shooter_maker.cpp timer.cpp main.cpp -lSDL -lSDL_image -Xlinker -zmuldefs 

--Compile success!Run all right!--

When I try to compile in windows with same command:
error: unrecognized option '-zmuldefs'

Uh oh... Why!??I use same code and same command!!!
The game compile and run all right in linux but not windows.Why!???!?!?!??!?
I don't post it here because it is too big...

Please help,Thank in advance.
Last edited on
The -z linker option is not valid on Windows.

Using it indicates that there is a problem with your source code and/or build system. Try to write your code so that you don't need the -z option and then try compiling on Windows again.

Your compile line should then look like
1
2
g++ -o scrolling_shooter_game ammo.cpp enemy_ammo.cpp enemy.cpp shooter.cpp \  
	enemy_maker.cpp shooter_maker.cpp timer.cpp main.cpp -lSDL -lSDL_image

BTW, I would also make use of a Makefile or something...
Thanks for your help but That way not work...sorry for that :(
I got many multiple definition error after use that way...
The -Xlinker -zmuldefs is required because I got same error in linux when I compile without -Xlinker -zmuldefs
Is there any command that can replace -Xlinker -zmuldefs ??
And how to write the code that con compile without -z option?

Thanks.
Last edited on
As I understand it, the linker's 'ignore multiple definitions' option exists to make Solaris behave when compiling statically-linked binaries -- because Sun's build system is screwed-up.

You aren't compiling with static libs. Where are you getting multiple definition errors?
I got those error:
multiple definition of 'ammo'
first definied here
multiple definition of 'shooter'
first definied here
multiple definition of 'enemy'
first definied here
multiple definition of 'shooter'
first definied here
--!!very long!!--

I don't know why...I only know I got same error when I compile this game in linux without "-Xlinker -zmuldefs" command
Is there anyway to add -z command to windows?Is there another way to solve this problem?

Thanks.
There is no other way other than to fix the source code.
How to fix it?
Put all code into 2 files(1 .cpp file,1 .h file)?
Source code should look like this:

foo.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// foo.hpp
// Copyright, license, and other commentary goes here.

#pragma once
#ifndef A20365354_FOO_HPP
#define A20365354_FOO_HPP

#include <stuff>

namespace foo
  {

  bool bar( int a, int b );

  class baz
    {
    int quux( int x )
    };

  } // namespace foo

#endif 


foo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// foo.cpp
// Copyright, license, and other commentary goes here. (The same as before.)

#include <more-stuff>

#include "foo.hpp"

namespace foo
  {

  bool bar( int a, int b )
    {
    return a < b;
    }

  int baz::quux( int x )
    {
    ...
    }

  }


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
...

#include "foo.hpp"

using namespace std;  // if you want to do this
using namespace foo;  // likewise, if you want to do this

int main()
  {
  baz b;
  cout << bar( b.quux( 42 ), -7 ) << endl;
  return 0;
  }

Notice how the header files (.h and .hpp) have the guards in place so that you can #include them as often as you like without introducing multiple symbols.

Likewise, the header files only declare, or prototype, stuff. The source files (.cpp) #include what they need, and define, or actually create, stuff.

In the main program source, you can #include everything you need (prototyped via inclusion, defined elsewhere) and use it that way.

Then, when linking, all the separate source files (.cpp) are connected so that the program has all its parts.

Hope this helps.
Sorry,It can't help :(:(
I finded the problem code,but I don't know how to solve it...
main.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

const int screen_width = 640;
const int screen_height = 480;
const int screen_bpp = 32;

void apply_surface( int , int , SDL_Surface* , SDL_Surface* , SDL_Rect* clip );
bool check_collision( std::vector<SDL_Rect> & , std::vector<SDL_Rect> & );
int load_data( int , int );
//following is problem code
#ifndef MAIN_HPP
#define MAIN_HPP

SDL_Rect ammo_clip[2][16];
SDL_Rect healbar_clip[2];
SDL_Rect shooter_clip[2][15];
SDL_Rect number[10];
SDL_Rect selecticon;
SDL_Rect start;
SDL_Rect generation;
SDL_Rect level;
SDL_Rect latest_level;
SDL_Rect quit;
SDL_Rect yourock;
SDL_Rect gameover;
SDL_Rect lifes;
SDL_Rect life_icon;
SDL_Rect process;
SDL_Rect nextlevel;
SDL_Rect back;

SDL_Surface *ammo = NULL;
SDL_Surface *healbar = NULL;
SDL_Surface *morisermode = NULL;
SDL_Surface *select_icon = NULL;
SDL_Surface *lifes_icon = NULL;
SDL_Surface *shooter = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *text = NULL;

bool Quit;

#endif 

I got that error:
/tmp/ccdEfgP5.o:(.bss+0x2f8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x0): multiple definition of `ammo_clip'
/tmp/ccdEfgP5.o:(.bss+0x0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x100): multiple definition of `healbar_clip'
/tmp/ccdEfgP5.o:(.bss+0x100): first defined here
/tmp/ccrdZjmP.o:(.bss+0x120): multiple definition of `shooter_clip'
/tmp/ccdEfgP5.o:(.bss+0x120): first defined here
/tmp/ccrdZjmP.o:(.bss+0x220): multiple definition of `number'
/tmp/ccdEfgP5.o:(.bss+0x220): first defined here
/tmp/ccrdZjmP.o:(.bss+0x270): multiple definition of `selecticon'
/tmp/ccdEfgP5.o:(.bss+0x270): first defined here
/tmp/ccrdZjmP.o:(.bss+0x278): multiple definition of `start'
/tmp/ccdEfgP5.o:(.bss+0x278): first defined here
/tmp/ccrdZjmP.o:(.bss+0x280): multiple definition of `generation'
/tmp/ccdEfgP5.o:(.bss+0x280): first defined here
/tmp/ccrdZjmP.o:(.bss+0x288): multiple definition of `level'
/tmp/ccdEfgP5.o:(.bss+0x288): first defined here
/tmp/ccrdZjmP.o:(.bss+0x290): multiple definition of `latest_level'
/tmp/ccdEfgP5.o:(.bss+0x290): first defined here
/tmp/ccrdZjmP.o:(.bss+0x298): multiple definition of `quit'
/tmp/ccdEfgP5.o:(.bss+0x298): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2a0): multiple definition of `yourock'
/tmp/ccdEfgP5.o:(.bss+0x2a0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2a8): multiple definition of `gameover'
/tmp/ccdEfgP5.o:(.bss+0x2a8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2b0): multiple definition of `lifes'
/tmp/ccdEfgP5.o:(.bss+0x2b0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2b8): multiple definition of `life_icon'
/tmp/ccdEfgP5.o:(.bss+0x2b8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2c0): multiple definition of `process'
/tmp/ccdEfgP5.o:(.bss+0x2c0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2c8): multiple definition of `nextlevel'
/tmp/ccdEfgP5.o:(.bss+0x2c8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2d0): multiple definition of `back'
/tmp/ccdEfgP5.o:(.bss+0x2d0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2d8): multiple definition of `ammo'
/tmp/ccdEfgP5.o:(.bss+0x2d8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2dc): multiple definition of `healbar'
/tmp/ccdEfgP5.o:(.bss+0x2dc): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2e8): multiple definition of `lifes_icon'
/tmp/ccdEfgP5.o:(.bss+0x2e8): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2e0): multiple definition of `morisermode'
/tmp/ccdEfgP5.o:(.bss+0x2e0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2e4): multiple definition of `select_icon'
/tmp/ccdEfgP5.o:(.bss+0x2e4): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2ec): multiple definition of `shooter'
/tmp/ccdEfgP5.o:(.bss+0x2ec): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2f4): multiple definition of `text'
/tmp/ccdEfgP5.o:(.bss+0x2f4): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2f0): multiple definition of `screen'
/tmp/ccdEfgP5.o:(.bss+0x2f0): first defined here
/tmp/ccrdZjmP.o:(.bss+0x2f8): multiple definition of `Quit'
/tmp/ccdEfgP5.o:(.bss+0x2f8): first defined here
and much more...


please help,Thank you.
Last edited on
You're missing the extern on your declaration. It can be fixed in a straight forward way.

In your header file, do the following:
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef DEFINE_EXTERNS
#define EXTERN extern
#else
#define EXTERN
#endif

EXTERN SDL_Rect ammo_clip[2][16];
EXTERN SDL_Rect healbar_clip[2];
EXTERN SDL_Rect shooter_clip[2][15];
EXTERN SDL_Rect number[10];
EXTERN SDL_Rect selecticon;
// ... and so on 


In one source file, probably the one with main(), do the following (assuming the header is called main.hpp):
1
2
#define DEFINE_EXTERNS
#include "main.hpp" 


This pattern will define your global variables in the main module and declare them in the rest.

BTW, why do you have global variables to begin with? Shouldn't these things be members of some class?
Last edited on
Yu-ho! It's work!!!Thanks!kbw! :):):):):):)
Also thanks to Duoas because he/she told me "The -z linker option is not valid on Windows." and gave me the solution( even it not work )
Last edited on
Topic archived. No new replies allowed.