tboox / tbox

🎁 A glib-like multi-platform c library
https://docs.tboox.org
Apache License 2.0
4.89k stars 725 forks source link

tbox无法在Windows下的clang工具链上编译 #258

Closed jingkaimori closed 6 months ago

jingkaimori commented 6 months ago

描述问题

在Windows 10平台上,从Visual Studio Installer中安装clang,并将clang加入Path环境变量,此时编译tbox不通过,报错信息显示rand_s函数未定义,推测为clang的宏展开逻辑和msvc不同所致

期待的结果

编译不报错

错误信息

> xmake config --toolchain=clang --hash=true --charset=true --force-utf8=true
checking for platform ... windows
checking for architecture ... x64
checking for wchar ... no
checking for libc_memmem ... no
checking for libc_strlcpy ... no
checking for libc_strcasecmp ... no
checking for libc_strcasestr ... no
checking for libc_strncasecmp ... no
checking for libc_memcpy ... ok
checking for libc_memset ... ok
checking for libc_strncpy ... ok
checking for libc_strcat ... ok
checking for libc_memmove ... ok
checking for libc_wcscpy ... ok
checking for libc_memcmp ... ok
checking for libc_strcpy ... ok
checking for libc_strncat ... ok
checking for libc_strnlen ... ok
checking for libc_strcmp ... ok
checking for libc_strstr ... ok
checking for libc_strrchr ... ok
checking for libc_strlen ... ok
checking for libc_strchr ... ok
checking for libc_strncmp ... ok
checking for libc_wcsncpy ... ok
checking for libc_wcsncat ... ok
checking for libc_wcscat ... ok
checking for libc_wcslcpy ... no
checking for libc_wcslen ... ok
checking for libc_wcsnlen ... ok
checking for libc_wcscasestr ... no
checking for libc_wcsstr ... ok
checking for libc_wcscmp ... ok
checking for libc_wcscasecmp ... no
checking for libc_gettimeofday ... no
checking for libc_wcsncasecmp ... no
checking for libc_wcsncmp ... ok
checking for libc_gmtime ... ok
checking for libc_mktime ... ok
checking for libc_wcstombs ... ok
checking for libc_mbstowcs ... ok
checking for libc_localtime ... ok
checking for libc_signal ... ok
checking for libc_setjmp ... ok
checking for libc_sigsetjmp ... no
checking for libc_backtrace ... no
checking for libc_kill ... no
checking for libc_setlocale ... ok
checking for libc_fputs ... ok
checking for libc_fgets ... ok
checking for libc_fgetc ... ok
checking for libc_ungetc ... ok
checking for libc_srandom ... no
checking for libc_random ... no
checking for libm_sincos ... no
checking for libc_fputc ... ok
checking for libc_fread ... ok
checking for libc_fwrite ... ok
checking for libm_sincosf ... no
checking for libm_log2 ... ok
checking for libm_log2f ... ok
checking for libm_sqrt ... ok
checking for libm_sqrtf ... ok
checking for libm_acos ... ok
checking for libm_acosf ... ok
checking for libm_asin ... ok
checking for libm_asinf ... ok
checking for libm_pow ... ok
checking for libm_powf ... ok
checking for libm_fmod ... ok
checking for libm_fmodf ... ok
checking for libm_tan ... ok
checking for libm_tanf ... ok
checking for libm_atan ... ok
checking for libm_atanf ... ok
checking for libm_atan2 ... ok
checking for libm_atan2f ... ok
checking for libm_cos ... ok
checking for libm_cosf ... ok
checking for libm_sin ... ok
checking for libm_sinf ... ok
checking for libm_exp ... ok
checking for libm_expf ... ok
checking for windows__InterlockedExchange8 ... ok
checking for windows__InterlockedExchange ... ok
checking for windows__InterlockedExchangeAdd ... ok
checking for windows__InterlockedOr8 ... ok
checking for windows__InterlockedCompareExchange ... ok
checking for windows__InterlockedCompareExchange64 ... ok
checking for windows__InterlockedExchangeAdd64 ... ok
checking for windows__InterlockedOr8_nf ... no
checking for windows__InterlockedExchange_nf ... no
checking for windows__InterlockedExchange8_nf ... no
checking for windows__InterlockedExchangeAdd64_nf ... no
checking for windows__InterlockedExchangeAdd_nf ... no
checking for windows__InterlockedExchange_acq ... no
checking for windows__InterlockedCompareExchange_nf ... no
checking for windows__InterlockedExchange8_acq ... no
checking for windows__InterlockedOr8_acq ... no
checking for windows__InterlockedCompareExchange64_nf ... no
checking for valgrind_VALGRIND_STACK_REGISTER ... no
checking for windows__InterlockedExchangeAdd_acq ... no
checking for keyword_thread ... no
checking for keyword_thread_local ... no
checking for feature_anonymous_union ... ok
checking for windows__InterlockedExchangeAdd64_acq ... no
checking for windows__InterlockedCompareExchange64_acq ... no
checking for windows__InterlockedCompareExchange_acq ... no
checking for windows__InterlockedExchange_rel ... no
checking for windows__InterlockedExchange8_rel ... no
checking for windows__InterlockedOr8_rel ... no
checking for windows__InterlockedExchangeAdd_rel ... no
checking for windows__InterlockedExchangeAdd64_rel ... no
checking for windows__InterlockedCompareExchange_rel ... no
checking for windows__InterlockedCompareExchange64_rel ... no
generating src\tbox\tbox.config.h.in ... ok
warning: add_cxflags("/utf-8") is ignored, please pass `{force = true}` or call `set_policy("check.auto_ignore_flags", false)` 
if you want to set it.
> xmake build   
[  0%]: cache compiling.release src\tbox\tbox.c
...
[  7%]: cache compiling.release src\tbox\libc\stdlib\random.c
[  7%]: cache compiling.release src\tbox\libc\stdlib\stdlib.c
[  7%]: cache compiling.release src\tbox\libc\stdlib\wcstombs.c
[  8%]: cache compiling.release src\tbox\libc\string\memcmp.c
[  8%]: cache compiling.release src\tbox\libc\string\memcpy.c
[  8%]: cache compiling.release src\tbox\libc\string\memdup.c
[  8%]: cache compiling.release src\tbox\libc\string\memmem.c
[  8%]: cache compiling.release src\tbox\libc\string\memmov.c
[  9%]: cache compiling.release src\tbox\libc\string\memset.c
[  9%]: cache compiling.release src\tbox\libc\string\strcat.c
[  9%]: cache compiling.release src\tbox\libc\string\strchr.c
[  9%]: cache compiling.release src\tbox\libc\string\strcmp.c
[ 10%]: cache compiling.release src\tbox\libc\string\strcpy.c
[ 10%]: cache compiling.release src\tbox\libc\string\strdup.c
[ 10%]: cache compiling.release src\tbox\libc\string\strichr.c
error: src\tbox\math\random/../../platform/windows/random.c:39:9: error: call to undeclared function 'rand_s'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   39 |     if (rand_s(&number) == 0)
      |         ^
src\tbox\math\random/../../platform/windows/random.c:39:9: note: did you mean 'rand'?
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt\stdlib.h:352:37: note: 'rand' declared here
  352 | _Check_return_ _ACRTIMP int __cdecl rand(void);
      |                                     ^
1 error generated.
  > in src\tbox\math\random\random.c
warning: add_cxflags("/utf-8") is ignored, please pass `{force = true}` or call `set_policy("check.auto_ignore_flags", false)` 
if you want to set it.

相关环境

在Windows 10平台上,从Visual Studio Installer中安装clang,并将clang加入Path环境变量。

xmake 2.8.9和2.9.1都不行

> clang --version
clang version 17.0.3
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin
> xmake --version
xmake v2.8.9+HEAD.cb1b65054, A cross-platform build utility based on Lua
Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io
xmake --version  
xmake v2.9.1+dev.e642997ba, A cross-platform build utility based on Lua
Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io

其他信息

暂无

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: tbox cannot be compiled on clang toolchain under Windows

waruqi commented 6 months ago

再试试,dev

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


Try again, dev

jingkaimori commented 6 months ago

dev上已经修复

Issues-translate-bot commented 6 months ago

Bot detected the issue body's language is not English, translate it automatically.


It has been fixed on dev