NagyD / SDLPoP

An open-source port of Prince of Persia, based on the disassembly of the DOS version.
GNU General Public License v3.0
1.1k stars 141 forks source link

Build failure on Fedora Linux #309

Closed mattiaverga closed 1 year ago

mattiaverga commented 1 year ago

I'm trying to build SDLPoP on Fedora, but I get build failures due to some implicit-function-declaration errors:

/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c:2138:46: error: implicit declaration of function ‘strdup’; did you mean ‘strcmp’? [-Werror=implicit-function-declaration]
 2138 |                         sound_names[index] = strdup(name);
      |                                              ^~~~~~
      |                                              strcmp
/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c:2138:44: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
 2138 |                         sound_names[index] = strdup(name);
      |                                            ^
/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c: In function ‘load_sound’:
/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c:2181:43: error: implicit declaration of function ‘fileno’; did you mean ‘d_fileno’? [-Werror=implicit-function-declaration]
 2181 |                                 if (fstat(fileno(fp), &info))
      |                                           ^~~~~~
      |                                           d_fileno
In file included from /builddir/build/BUILD/SDLPoP-1.23/src/seg009.c:21:
/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c: In function ‘draw_overlay’:
/builddir/build/BUILD/SDLPoP-1.23/src/seg009.c:2628:63: error: implicit declaration of function ‘strnlen’; did you mean ‘strlen’? [-Werror=implicit-function-declaration]
 2628 |                         int extra_numeric_chars = MAX(0, (int)strnlen(timer_text, sizeof(timer_text)) - 8);
      |                                                               ^~~~~~~
/builddir/build/BUILD/SDLPoP-1.23/src/common.h:59:24: note: in definition of macro ‘MAX’
   59 | #define MAX(a,b) ((a)>(b)?(a):(b))
      |                        ^

AFAIK both fileno and strnlen aren't part of standard library.

NagyD commented 1 year ago

AFAIK both fileno and strnlen aren't part of standard library.

According to the pages below, they should be part of the standard library, but some feature test macros should be defined before including any headers (in common.h). https://linux.die.net/man/3/fileno https://linux.die.net/man/3/strnlen strdup needs macros as well: https://linux.die.net/man/3/strdup

You could try adding these in common.h, before the #includes:

#define _XOPEN_SOURCE 700
#define _POSIX_SOURCE 200809L

However, it might be that these macros are not defined by default exactly because your system does not support the features behind them.

mattiaverga commented 1 year ago

Thanks, I've managed to build successfully by commenting out set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99") (I suppose the -std=c99 was wrong). However, my purpose was to package SDLPoP in Fedora repositories, but I later discovered that the data resources location cannot be configured to be out of the binary directory, so... never mind.