Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit e3f14fa2ffb218a46eeebedb95f26f3d04d5508b breaks Linux build #125

Open
assarbad opened this issue Jan 24, 2025 · 1 comment
Open

Comments

@assarbad
Copy link

Hey, so I tried to build this on Linux (HEAD at f8b2cf9) and ran into the following error:

cc  -DGAMEDLL -DQAGAME -fPIC -fvisibility=hidden -DARCH_64 -Wall -fno-strict-aliasing -pipe -DUSE_ICON -DARCH_STRING=\"x86_64\" -m64 -DNO_GZIP -Icode/zlib-1.2.11 -DUSE_INTERNAL_JPEG -Icode/jpeg-8c -DBUILD_FREETYPE -Icode/freetype-2.9/include -DFT2_BUILD_LI
BRARY -DUSE_LOCAL_HEADERS -DPRODUCT_VERSION=\"5.0\" -Wformat=2 -Wformat-security -Wno-format-nonliteral -Wstrict-aliasing=2 -Wmissing-format-attribute -Wdisabled-optimization -MMD -DNDEBUG -O3 -o build/release-linux-x86_64/main/game/ai_cast_funcs.o -c code
/game/ai_cast_funcs.c
code/game/ai_cast_funcs.c: In function ‘BG_ParseSurvivalTable’:
code/game/ai_cast_funcs.c:5862:63: error: passing argument 2 of ‘PC_String_ParseNoAlloc’ from incompatible pointer type [-Wincompatible-pointer-types]
 5862 |                         if ( !PC_String_ParseNoAlloc( handle, &svParams.announcerSound[0], MAX_QPATH ) ) {
      |                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                               |
      |                                                               char (*)[64]
In file included from code/game/g_local.h:34,
                 from code/game/ai_cast_funcs.c:39:
code/game/bg_public.h:1809:52: note: expected ‘char *’ but argument is of type ‘char (*)[64]’
 1809 | qboolean PC_String_ParseNoAlloc( int handle, char *out, size_t size );
      |                                              ~~~~~~^~~
code/game/ai_cast_funcs.c:5869:63: error: passing argument 2 of ‘PC_String_ParseNoAlloc’ from incompatible pointer type [-Wincompatible-pointer-types]
 5869 |                         if ( !PC_String_ParseNoAlloc( handle, &soundPath, MAX_QPATH ) ) {
      |                                                               ^~~~~~~~~~
      |                                                               |
      |                                                               char (*)[64]
code/game/bg_public.h:1809:52: note: expected ‘char *’ but argument is of type ‘char (*)[64]’
 1809 | qboolean PC_String_ParseNoAlloc( int handle, char *out, size_t size );
      |                                              ~~~~~~^~~
code/game/ai_cast_funcs.c:5875:33: error: implicit declaration of function ‘sprintf_s’; did you mean ‘sprintf’? [-Wimplicit-function-declaration]
 5875 |                                 sprintf_s(msg, 64, "announcerSound[%d] out of range. Increase ANNOUNCE_SOUNDS_COUNT", i - 1 );
      |                                 ^~~~~~~~~
      |                                 sprintf
code/game/ai_cast_funcs.c:5878:33: error: implicit declaration of function ‘strcpy_s’; did you mean ‘strcpy’? [-Wimplicit-function-declaration]
 5878 |                                 strcpy_s( svParams.announcerSound[i - 1], MAX_QPATH, soundPath );
      |                                 ^~~~~~~~
      |                                 strcpy
make[2]: *** [Makefile:2842: build/release-linux-x86_64/main/game/ai_cast_funcs.o] Error 1

It seems to correlate to commit e3f14fa.

I am able to work around the incompatible pointer type by invoking make as follows:

make -j $(nproc) V=1 CFLAGS=-Wno-incompatible-pointer-types

Going by cppreference.com sprintf_s is C11 and newer and so is strcpy_s But GLIBC doesn't implement either. So no cheap workaround for these newly introduced calls. Strangely the same commit used snprintf — which would be available — around line 380 but then resorts to sprintf_s here (line 5875).

What worked for me in the past for other projects was to gloss over those differences with a common set of glue "primitives" for this sort of functionality. Could be as cheap as macros or static inline wrappers.


Compiler is:

$ cc --version
cc (GCC) 14.2.1 20240910
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@assarbad
Copy link
Author

Based on predef to detect GLIBC I added the following workaround for me locally:

diff --git a/code/game/ai_cast_funcs.c b/code/game/ai_cast_funcs.c
index 31e0841..c083e3d 100644
--- a/code/game/ai_cast_funcs.c
+++ b/code/game/ai_cast_funcs.c
@@ -32,14 +32,19 @@ If you have questions concerning this license or the applicable additional terms
  * desc:               Wolfenstein AI Character Decision Making
  *
 */

 #include <stdlib.h> // For rand()
 #include <stdio.h>  // For snprintf()

+#if (__GLIBC__) || (__GNU_LIBRARY__)
+#define sprintf_s snprintf
+#define strcpy_s(dest, destsz, src) strncpy(dest, src, destsz)
+#endif
+
 #include "g_local.h"
 #include "../qcommon/q_shared.h"
 #include "../botlib/botlib.h"      //bot lib interface
 #include "../botlib/be_aas.h"
 #include "../botlib/be_ea.h"
 #include "../botlib/be_ai_gen.h"
 #include "../botlib/be_ai_goal.h"

This builds together with make -j $(nproc) V=1 CFLAGS=-Wno-incompatible-pointer-types, but it's just a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant