joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.76k stars 381 forks source link

Build fails on Gentoo Linux (fix included) #1780

Closed fonic closed 1 month ago

fonic commented 4 years ago

Describe the bug Build using build-debug fails on Gentoo Linux (amd64, stable, desktop profile) due to errors related to zlib:

In file included from ../include/zip.h:54,
                 from dosbox.cpp:77:
../include/ioapi.h:132:51: error: expected initializer before ‘OF’
  132 | typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, const char* filename, int mode));
      |                                                   ^~
../include/ioapi.h:133:51: error: expected initializer before ‘OF’
  133 | typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size));
      |                                                   ^~
../include/ioapi.h:134:51: error: expected initializer before ‘OF’
  134 | typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
      |                                                   ^~
../include/ioapi.h:135:51: error: expected initializer before ‘OF’
  135 | typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream));
      |                                                   ^~
../include/ioapi.h:136:51: error: expected initializer before ‘OF’
  136 | typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
      |                                                   ^~
../include/ioapi.h:138:51: error: expected initializer before ‘OF’
  138 | typedef long     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream));
      |                                                   ^~
../include/ioapi.h:139:51: error: expected initializer before ‘OF’
  139 | typedef long     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin));
      |                                                   ^~
../include/ioapi.h:145:5: error: ‘open_file_func’ does not name a type
  145 |     open_file_func      zopen_file;
      |     ^~~~~~~~~~~~~~
../include/ioapi.h:146:5: error: ‘read_file_func’ does not name a type
  146 |     read_file_func      zread_file;
      |     ^~~~~~~~~~~~~~
../include/ioapi.h:147:5: error: ‘write_file_func’ does not name a type
  147 |     write_file_func     zwrite_file;
      |     ^~~~~~~~~~~~~~~
../include/ioapi.h:148:5: error: ‘tell_file_func’ does not name a type
  148 |     tell_file_func      ztell_file;
      |     ^~~~~~~~~~~~~~
../include/ioapi.h:149:5: error: ‘seek_file_func’ does not name a type
  149 |     seek_file_func      zseek_file;
      |     ^~~~~~~~~~~~~~
../include/ioapi.h:150:5: error: ‘close_file_func’ does not name a type
  150 |     close_file_func     zclose_file;
      |     ^~~~~~~~~~~~~~~
../include/ioapi.h:151:5: error: ‘testerror_file_func’ does not name a type
  151 |     testerror_file_func zerror_file;
      |     ^~~~~~~~~~~~~~~~~~~
../include/ioapi.h:155:51: error: expected initializer before ‘OF’
  155 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream));
      |                                                   ^~

[and many more]

There's a rather simple fix:

diff -Naurp a/include/ioapi.h b/include/ioapi.h
--- a/include/ioapi.h   2020-08-03 21:18:18.606933344 +0200
+++ b/include/ioapi.h   2020-08-03 21:19:30.329932231 +0200
@@ -105,6 +105,10 @@ typedef unsigned long long int ZPOS64_T;
 extern "C" {
 #endif

+#ifdef _Z_OF
+#undef OF
+#define OF _Z_OF
+#endif

 #define ZLIB_FILEFUNC_SEEK_CUR (1)
 #define ZLIB_FILEFUNC_SEEK_END (2)

With this fix applied, DOSBox-X builds fine without any errors.

Source of fix: issue #26 of project godotengine/godot here on GitHub. It would seem this issue stems from Gentoo sanitizing zlib's headers. I'm not sure if this fix is safe for other build environments (comments of the issue linked above suggests it should be).

To Reproduce On Gentoo Linux, run the following commands:

# git clone https://github.com/joncampbell123/dosbox-x.git dosbox-x
# cd dosbox-x
# ./build-debug

Expected behavior DOSBox-X should build without errors.

Screenshots (none)

Environment (please complete the following information):

Additional context (none)

fierevere commented 3 years ago

Thanks for patch, works for me.

Wengier commented 3 years ago

Since this appears to be very helpful, I have already included it in PR #2218. Thanks for providing the fix!