Changes to build on Ubuntu 12.04 LTS (64-bit)

The main forum for zSILENCER, everything can be here.

Changes to build on Ubuntu 12.04 LTS (64-bit)

Postby Zoinky » Tue Apr 08, 2014 3:07 am

Hi, since the Linux binary on the download page doesn't run on my machine (it seems to want a 32-bit version of SDL, and I don't particularly want to compile one), I tried to compile from source. There are a couple of things preventing successful compilation on Ubuntu 12.04 (64-bit), however. In case there's someone else in the same situation, I thought I would share the changes I made to get zsilencer to compile and run on my machine. They're pretty minor, but they may be of use to someone in the same situation. If the changes don't break the build for any other systems, perhaps the changes could also be adopted in mainline?

Here is a summary of the changes. For a patchfile, see below (git checkout, then git apply <patchfilefrombelow.patch>, then build as normal: aclocal, autoconf, automake --add-missing, ./configure and make).

  • Instead of using AM_CPPFLAGS and AM_LDFLAGS in Makefile.am, I've used (in configure.ac) the convenient sdl2-config and pkg-config utilities to get the correct paths and compilation flags (for CFLAGS, CXXFLAGS and LIBS) for SDL and SDL_mixer, since they're not necessarily in the directory indicated. And AM_LDFLAGS puts the libraries to link with in the wrong part of the command line for g++, which causes the linker to fail (on my machine at least)
  • Renderer::DrawMessage() casts the result of strchr() to an int, which g++ will not allow (int is not big enough to hold the pointer returned by this function and cannot be cast as a result). The -fpermissive option could reduce this to a warning, but I opted to change the linelength variable to a size_t instead of an int, which I think will be the right size on 32-bit and 64-bit systems.
  • g++ does not like an sprintf() format used in game.cpp, line 5531 (%0.2X) as it feels the 0 is redundant. I've removed the 0 so it stops complaining.
  • robot.cpp now #includes "fixedcannon.h" instead of "Fixedcannon.h" (caps typo)

Patch file is here:
Code: Select all
diff --git a/Makefile.am b/Makefile.am
index c84810f..bd46c0d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,3 @@
-AM_CPPFLAGS = -I/usr/include/SDL2
-AM_LDFLAGS = -lSDL2 -lSDL2_mixer
 bin_PROGRAMS = zSILENCERlinux
 zSILENCERlinux_SOURCES = audio.cpp basedoor.cpp baseexit.cpp terminal.cpp bipedal.cpp \
                blasterprojectile.cpp bodypart.cpp button.cpp \
diff --git a/configure.ac b/configure.ac
index d5e5072..47d0d06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,4 +5,7 @@ AC_PROG_CC
 AC_CONFIG_FILES([
  Makefile
 ])
+CFLAGS="$CFLAGS `sdl2-config --cflags` `pkg-config SDL2_mixer --cflags`"
+CXXFLAGS="$CXXFLAGS `sdl2-config --cflags` `pkg-config SDL2_mixer --cflags`"
+LIBS="$LIBS `sdl2-config --libs` `pkg-config SDL2_mixer --libs`"
 AC_OUTPUT
\ No newline at end of file
diff --git a/game.cpp b/game.cpp
index 366f097..2ac7042 100755
--- a/game.cpp
+++ b/game.cpp
@@ -5528,7 +5528,7 @@ std::string Game::StringFromHash(unsigned char (*hash)[20]){
    memset(hashstring, 0, sizeof(hashstring));
    for(int i = 0; i < 20; i++){
       unsigned char byte = (*hash)[i];
-      sprintf(&hashstring[i * 2], "%0.2X", byte);
+      sprintf(&hashstring[i * 2], "%.2X", byte);
    }
    return std::string(hashstring);
 }
@@ -5800,4 +5800,4 @@ bool Game::HandleSDLEvents(void){
       }
    }
    return true;
-}
\ No newline at end of file
+}
diff --git a/renderer.cpp b/renderer.cpp
index 49e5989..33161fb 100755
--- a/renderer.cpp
+++ b/renderer.cpp
@@ -1648,11 +1648,11 @@ void Renderer::DrawMessage(Surface * surface){
    if(!world.message_i){
       return;
    }
-   int linelength = (int)strchr(world.message, '\n');
+   size_t linelength = (size_t)strchr(world.message, '\n');
    if(!linelength){
       linelength = strlen(world.message);
    }else{
-      linelength -= (int)world.message;
+      linelength -= (size_t)world.message;
    }
    int liney = 60;
    Uint8 color = 208;
@@ -1686,9 +1686,9 @@ void Renderer::DrawMessage(Surface * surface){
          liney = 200;
       break;
    }
-   int nextline = linelength;
+   size_t nextline = linelength;
    int line = 0;
-   for(int i = 0; i < strlen(world.message); i++){
+   for(size_t i = 0; i < strlen(world.message); i++){
       if(i >= world.message_i){
          break;
       }
@@ -1723,11 +1723,11 @@ void Renderer::DrawMessage(Surface * surface){
       DrawText(surface, ((640 - (linelength * textwidth)) / 2) + (textwidth * (linelength - nextline)), liney, temp, textbank, textwidth, false, color, brightness);
       nextline--;
       if(nextline < 0){
-         linelength = (int)strchr(&world.message[i + 1], '\n');
+         linelength = (size_t)strchr(&world.message[i + 1], '\n');
          if(!linelength){
             linelength = strlen(&world.message[i + 1]);
          }else{
-            linelength -= (int)&world.message[i + 1];
+            linelength -= (size_t)&world.message[i + 1];
          }
          nextline = linelength;
          if(line == 0 && world.messagetype >= 10){
diff --git a/robot.cpp b/robot.cpp
index 3610505..465d7ff 100755
--- a/robot.cpp
+++ b/robot.cpp
@@ -2,7 +2,7 @@
 #include "rocketprojectile.h"
 #include "plasmaprojectile.h"
 #include "player.h"
-#include "Fixedcannon.h"
+#include "fixedcannon.h"
 #include "plume.h"
 
 Robot::Robot() : Object(ObjectTypes::ROBOT){
@@ -455,4 +455,4 @@ void Robot::Melee(Object & object, World & world){
    damageprojectile.shielddamage = 60;
    damageprojectile.ownerid = id;
    object.HandleHit(world, 50, 50, damageprojectile);
-}
\ No newline at end of file
+}

Zoinky
 
Posts: 6
Joined: Sun Apr 06, 2014 4:59 pm

Re: Changes to build on Ubuntu 12.04 LTS (64-bit)

Postby admin » Tue Apr 08, 2014 3:56 am

Excellent. Yeah the linux tar.gz hasn't even been updated since version 00021 and I used to put a 32 and 64 bit binary in, but have only done the 32 bit as of late. Thanks for these patches, added :) . I went ahead and sort of redid the strchr things, great finds.
User avatar
admin
Site Admin
 
Posts: 26
Joined: Sun Jul 28, 2013 2:38 pm

Re: Changes to build on Ubuntu 12.04 LTS (64-bit)

Postby Zoinky » Tue Apr 08, 2014 1:08 pm

Great, thanks. I just cloned the git repository and it builds without any errors/warnings now (unless you turn on -Wall :P).
Zoinky
 
Posts: 6
Joined: Sun Apr 06, 2014 4:59 pm


Return to Main Forum

Who is online

Users browsing this forum: No registered users and 1 guest