-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Errors when building SDL3.dll with -DSDL_LIBC=OFF #11759
Comments
For SDL_immdevice.c, I guess we hit it for referencing And, how come we don't hit this issue in SDL2? |
SDL3 does not use Removing the |
That's the wrong thing to do: I guess that sneaked in with the dlmalloc upgrade to 2.8.6
Yes: That's the right thing to do |
Correction, |
Maybe something like this? (inspired from dynapi.c) diff --git a/src/SDL_hashtable.c b/src/SDL_hashtable.c
index 192121a..5405cbd 100644
--- a/src/SDL_hashtable.c
+++ b/src/SDL_hashtable.c
@@ -22,8 +22,27 @@
#include "SDL_hashtable.h"
// XXX: We can't use SDL_assert here because it's going to call into hashtable code
-#include <assert.h>
-#define HT_ASSERT(x) assert(x)
+#ifdef NDEBUG
+#define HT_ASSERT(x) (void)(0)
+#else
+/* This is not declared in any header, although it is shared between some
+ parts of SDL, because we don't want anything calling it without an
+ extremely good reason. */
+extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
+static void HT_ASSERT_FAIL(const char *msg)
+{
+ const char *caption = "SDL_HashTable Assertion Failure!";
+ (void)caption;
+#if (defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
+ MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONERROR);
+#elif defined(HAVE_STDIO_H)
+ fprintf(stderr, "\n\n%s\n%s\n\n", caption, msg);
+ fflush(stderr);
+#endif
+ SDL_ExitProcess(-1);
+}
+#define HT_ASSERT(x) if (!(x)) HT_ASSERT_FAIL("SDL_HashTable Assertion Failure: " #x)
+#endif
typedef struct SDL_HashItem
{ |
P.S.: About assert.h in SDL_HashTable.c: Does Xcode define |
(CC @slouken about that.) |
I don't believe it does, but you should be able to use assert() unconditionally.
It will typically disable itself in release builds the same way.
How will assert() disable itself if NDBEUG isn't defined?
Although looking at the diff, that's completely irrelevant.
Um? Which diff?
|
No, it does not. |
Never mind, I was typing ahead of my brain. :) Your question is answered above. |
It should. Should it not? |
It's not required, but done on Windows by convention. I added it in ec29d3f |
That looks good for me. I added it to #11761 |
I hope I haven't made a mess with msg and caption and stuff in there :) |
Perhaps we should add a |
@slouken to decide? P.S.: SDL_ttf has the same hashtable code duplicated in it. Why are we not making hashtable a public api instead? |
Sounds good to me. Should we do that for other assert implementations (if we don't already?)
Because it's an ugly, unwieldy API and most people use languages with other implementations available. @icculus and I talked about it and agreed to keep it simple so anyone can grab it and drop it in their project if they want it. |
There are no other non-SDL_assert implementations. (I've added this to #11761) |
Was this released? I'm getting errors trying to compile SDL3 with File: abc.sh
#!/bin/sh
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DSDL_LIBC=OFF \
-DSDL_STATIC=ON \
-DSDL_SHARED=OFF \
-DSDL_INSTALL_DOCS=OFF \
-DSDL_TEST_LIBRARY=OFF 30%] Building C object CMakeFiles/SDL3-static.dir/src/hidapi/SDL_hidapi.c.o
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c: In function ‘SDL_GetCPUCacheLineSize’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:870:23: error: implicit declaration of function ‘fopen’ [-Wimplicit-function-declaration]
870 | FILE *f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:25:1: note: ‘fopen’ is defined in header ‘<stdio.h>’; this is probably fixable by adding ‘#include <stdio.h>’
24 | #include "SDL_cpuinfo_c.h"
+++ |+#include <stdio.h>
25 |
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:870:23: error: initialization of ‘FILE *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
870 | FILE *f = fopen("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", "r");
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:873:21: error: implicit declaration of function ‘fscanf’ [-Wimplicit-function-declaration]
873 | if (fscanf(f, "%d", &size) == 1) {
| ^~~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:873:21: note: include ‘<stdio.h>’ or provide a declaration of ‘fscanf’
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:873:21: warning: incompatible implicit declaration of built-in function ‘fscan’ [-Wbuiltin-declaration-mismatch]
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:873:21: note: include ‘<stdio.h>’ or provide a declaration of ‘fscanf’
[ 27%] Building C object CMakeFiles/SDL3-static.dir/src/io/SDL_iostream.c.o
[ 30%] Building C object CMakeFiles/SDL3-static.dir/src/main/SDL_main_callbacks.c.o
[ 30%] Building C object CMakeFiles/SDL3-static.dir/src/io/SDL_asyncio.c.o
[ 30%] Building C object CMakeFiles/SDL3-static.dir/src/joystick/SDL_gamepad.c.o
[ 31%] Building C object CMakeFiles/SDL3-static.dir/src/locale/SDL_locale.c.o
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/cpuinfo/SDL_cpuinfo.c:876:17: error: implicit declaration of function ‘fclose’; did you mean ‘false’? [-Wimplicit-function-declaration]
876 | fclose(f);
| ^~~~~~
| false
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/SDL_log.c:427:20: warning: ‘GetLogPriorityPrefix’ defined but not used [-Wunused-function]
427 | static const char *GetLogPriorityPrefix(SDL_LogPriority priority)
| ^~~~~~~~~~~~~~~~~~~~
[ 31%] Building C object CMakeFiles/SDL3-static.dir/src/misc/SDL_url.c.o
[ 31%] Building C object CMakeFiles/SDL3-static.dir/src/joystick/controller_type.c.o
[ 31%] Building C object CMakeFiles/SDL3-static.dir/src/joystick/SDL_steam_virtual_gamepad.c.o
[ 32%] Building C object CMakeFiles/SDL3-static.dir/src/joystick/SDL_joystick.c.o
[ 32%] Building C object CMakeFiles/SDL3-static.dir/src/power/SDL_power.c.o
[ 34%] Building C object CMakeFiles/SDL3-static.dir/src/render/SDL_d3dmath.c.o
gmake[2]: *** [CMakeFiles/SDL3-static.dir/build.make:445: CMakeFiles/SDL3-static.dir/src/cpuinfo/SDL_cpuinfo.c.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
[ 35%] Building C object CMakeFiles/SDL3-static.dir/src/render/direct3d/SDL_shaders_d3d.c.o
[ 35%] Building C object CMakeFiles/SDL3-static.dir/src/render/direct3d/SDL_render_d3d.c.o
[ 37%] Building C object CMakeFiles/SDL3-static.dir/src/render/SDL_render_unsupported.c.o
[ 37%] Building C object CMakeFiles/SDL3-static.dir/src/render/SDL_render.c.o
[ 37%] Building C object CMakeFiles/SDL3-static.dir/src/render/SDL_yuv_sw.c.o
[ 37%] Building C object CMakeFiles/SDL3-static.dir/src/main/SDL_runapp.c.o
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘fd_seek’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:407:65: error: ‘errno’ undeclared (first use in this function)
407 | SDL_SetError("Couldn't get stream offset: %s", strerror(errno));
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:43:1: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
42 | #include "SDL_iostream_c.h"
+++ |+#include <errno.h>
43 |
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:407:65: note: each undeclared identifier is reported only once for each function it appears in
407 | SDL_SetError("Couldn't get stream offset: %s", strerror(errno));
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘fd_read’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:418:27: error: ‘errno’ undeclared (first use in this function)
418 | } while (bytes < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:418:27: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:418:36: error: ‘EINTR’ undeclared (first use in this function)
418 | } while (bytes < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:421:22: error: ‘EAGAIN’ undeclared (first use in this function)
421 | if (errno == EAGAIN) {
| ^~~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘fd_write’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:437:27: error: ‘errno’ undeclared (first use in this function)
437 | } while (bytes < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:437:27: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:437:36: error: ‘EINTR’ undeclared (first use in this function)
437 | } while (bytes < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:440:22: error: ‘EAGAIN’ undeclared (first use in this function)
440 | if (errno == EAGAIN) {
| ^~~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘fd_flush’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:456:28: error: ‘errno’ undeclared (first use in this function)
456 | } while (result < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:456:28: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:456:37: error: ‘EINTR’ undeclared (first use in this function)
456 | } while (result < 0 && errno == EINTR);
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘fd_close’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:470:76: error: ‘errno’ undeclared (first use in this function)
470 | status = SDL_SetError("Error closing datastream: %s", strerror(errno));
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:470:76: note: ‘errno’ is defined in header ‘<errno.h>’; this is probably fixable by adding ‘#include <errno.h>’
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c: In function ‘SDL_IOFromFD’:
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:499:17: error: storage size of ‘st’ isn’t known
499 | struct stat st;
| ^~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:500:30: error: implicit declaration of function ‘fstat’ [-Wimplicit-function-declaration]
500 | iodata->regular_file = ((fstat(fd, &st) == 0) && S_ISREG(st.st_mode));
| ^~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:500:54: error: implicit declaration of function ‘S_ISREG’ [-Wimplicit-function-declaration]
500 | iodata->regular_file = ((fstat(fd, &st) == 0) && S_ISREG(st.st_mode));
| ^~~~~~~
/home/benjaminadamson/Downloads/SDL-prerelease-3.1.10/src/io/SDL_iostream.c:499:17: warning: unused variable ‘st’ [-Wunused-variable]
499 | struct stat st; |
|
Is the DLL use case completed? |
Yes, I recently fixed this in #11761 Keep this issue open. I'm going to add a |
assert
in debug mode:SDL_hashtable.c.obj : error LNK2019: unresolved external symbol __imp__wassert referenced in function SDL_IterateHashTableKey
SDL/src/SDL_hashtable.c
Lines 24 to 26 in 0cb4a94
HRESULT_FROM_WIN32
win32 inlined function causes an issueSDL_immdevice.c.obj : error LNK2005: HRESULT_FROM_WIN32 already defined in SDL_malloc.c.obj
On my system,
HRESULT_FROM_WIN32
is a inlined function:#define FORCEINLINE __forceinline
mbtowc_s
andwcslen
:The text was updated successfully, but these errors were encountered: