lincity-ng / lincity-ng

City Simulation Game
GNU General Public License v2.0
411 stars 82 forks source link

Compilation failed on Raspberry Pi #144

Closed Srandista closed 2 months ago

Srandista commented 3 months ago

Hello. I tried to compile latest build on my Raspberry Pi with Raspberry Pi OS basted on Debian Bookworm, but compilation failed on following step:

/home/srandista/Downloads/lincity-ng/src/lincity/xmlloadsave.cpp: In member function ‘void XMLloadsave::loadGlobals()’:
/home/srandista/Downloads/lincity-ng/src/lincity/xmlloadsave.cpp:902:9: error: expected primary-expression before ‘}’ token
  902 |         }
      |         ^
gmake[2]: *** [src/lincity/CMakeFiles/lincity_lib.dir/build.make:356: src/lincity/CMakeFiles/lincity_lib.dir/xmlloadsave.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:386: src/lincity/CMakeFiles/lincity_lib.dir/all] Error 2
gmake: *** [Makefile:156: all] Error 2

Since the error message pointed to xmlloadsave.cpp, I tried to compile from commit before recent change in that file (d881eb2) and that went fine, it finished with successful build.

If you need any additional info or logs, just let me know.

Thank you.

Srandista commented 3 months ago

Just to specify, I use gcc 12.2.0 + cmake 3.25.1 in my environment.

Srandista commented 3 months ago

Same issue (with same gcc and cmake versions) is also reproducible on MX Linux 23 x64 based on Bookworm.

dbear496 commented 3 months ago

Thank you for opening an issue. I hadn't realized this was a problem because it compiled fine for me with gcc 14.1.1. I believe adding a semicolon to the end of line 901 will fix it:

found_global: ;

I'll draw up a PR with this change soon.

Srandista commented 3 months ago

Yeah, I tried to compile also on Xubuntu 24.04 with gcc 13.2.0 and there it went without issues. But since both Raspberry Pi OS and Xubuntu aren't rolling distros, I can't upgrade gcc to higher version, where it would pass the error.

dbear496 commented 3 months ago

For LinCity NG 2.10.2, I compiled the release binaries with Ubuntu 22.04 (using Docker) which uses libc version 2.35, but I compiled LinCity NG 2.11.0 with Arch, which is currently using libc version 2.39. I'm not really sure what to do about this; must I compile a separate release binary for every major version of every popular Linux distro? I have done a decent amount of research on how to create compatible binaries, and I couldn't find a good answer. If you know of a solution, then I'm all ears.

dbear496 commented 3 months ago

Please see if the changes in PR #146 fix the issues you are seeing. If you can successfully compile and run with those changes, then I will merge the changes into master.

Srandista commented 3 months ago

Thank you for quick fix! I was able to successfully compile lincity on both Xubuntu 22.04 and MX Linux without any errors.

I'm getting this warning during compilation, but that's just warning and I got the compiled and working binaries at the end.

/home/srandista/Downloads/lincity-ng/src/lincity/xmlloadsave.cpp: In member function ‘void XMLloadsave::loadGlobals()’:
/home/srandista/Downloads/lincity-ng/src/lincity/xmlloadsave.cpp:892:103: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘bool*’ [-Wformat=]
  892 |               if     (xml_tag == std::string("import_") + cname + "_enable") sscanf(xml_val.c_str(),"%d",&portConstructionGroup.tradeRule[c].take);
      |                                                                                                      ~^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                       |  |
      |                                                                                                       |  bool*
      |                                                                                                       int*
/home/srandista/Downloads/lincity-ng/src/lincity/xmlloadsave.cpp:893:103: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘bool*’ [-Wformat=]
  893 |               else if(xml_tag == std::string("export_") + cname + "_enable") sscanf(xml_val.c_str(),"%d",&portConstructionGroup.tradeRule[c].give);
      |                                                                                                      ~^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                       |  |
      |                                                                                                       |  bool*
      |                                                                                                       int*
[  4%] Linking CXX static library liblincity_lib.a
Srandista commented 3 months ago

Regarding compiling binaries for GitHub releases I won't be much of help, I'm just user, which learned how to compile binaries. But from my observations, it seems, that app is being compiled with gcc in a way, that you can load it only on systems with current glibc version and one bellow (so in case of 2.10.2 the glibc 2.34 is required). And since Arch is rolling distro with very latest glibc installed, the selection of OSes, where that binary would work is kinda limited (pretty much to just other rolling distros).

dbear496 commented 3 months ago

I'm looking into those warnings and assessing what the best fix may be.

As for binary compatibility, I may look into using Open Build Service, but for the time being, the most reliable way to get LinCity NG running is to compile from source.

dbear496 commented 3 months ago

I fixed that warning about the use of bool in sscanf. The changes should be merged into master in about 2 weeks.

Srandista commented 3 months ago

Since you're also trying to fix the warnings, I'll post here 2 more, that I can see in the output:

/home/srandista/Downloads/lincity-ng/src/lincity-ng/Dialog.cpp: In member function ‘void Dialog::gameStats()’:
/home/srandista/Downloads/lincity-ng/src/lincity-ng/Dialog.cpp:402:41: warning: ‘%s’ directive output may be truncated writing up to 1023 bytes into a region of size 564 [-Wformat-truncation=]
  402 |         snprintf (outf, maxlength,"%s - %s", _("Initial loaded scene"), given_scene);
      |                                         ^~                              ~~~~~~~~~~~
/home/srandista/Downloads/lincity-ng/src/lincity-ng/Dialog.cpp:402:18: note: ‘snprintf’ output 4 or more bytes (assuming 1027) into a destination of size 567
  402 |         snprintf (outf, maxlength,"%s - %s", _("Initial loaded scene"), given_scene);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/srandista/Downloads/lincity-ng/src/lincity-ng/main.cpp: In function ‘void initPhysfs(const char*)’:
/home/srandista/Downloads/lincity-ng/src/lincity-ng/main.cpp:222:44: warning: ‘const char* PHYSFS_getUserDir()’ is deprecated [-Wdeprecated-declarations]
  222 |     const char* userdir = PHYSFS_getUserDir();
      |                           ~~~~~~~~~~~~~~~~~^~
In file included from /home/srandista/Downloads/lincity-ng/src/lincity-ng/main.cpp:28:
/usr/include/physfs.h:792:25: note: declared here
  792 | PHYSFS_DECL const char *PHYSFS_getUserDir(void) PHYSFS_DEPRECATED;
      |                         ^~~~~~~~~~~~~~~~~

The one from xmlloadsave.cpp is indeed fixed in your fix branch.

dbear496 commented 3 months ago

The first one shouldn't be an issue. The second one is there for compatibility with previous LinCity-NG versions.

dbear496 commented 3 months ago

Are you using come compiler flags to enable warnings because I do not see the first warning on my end?

Srandista commented 3 months ago

That one I'm getting on Xubuntu 24.04 with gcc 13.2.0 + cmake 3.28.3 and standard compilation steps like on all other systems.