-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hi, I work on MSVC compiler testing, and we regularly build popular open-source project including box2d, with development builds of MSVC in order to find and fix regressions before they ship and cause problems for you.
Recently, as I build box2d with x86 as the target architecture from source with MSVC, I encountered the error as following:
C:\gitP\erincatto\box2d\src\core.c(118,8): error C2220: the following warning is treated as an error [C:\gitP\erincatto\box2d\build_x86\src\box2d.vcxproj]
C:\gitP\erincatto\box2d\src\core.c(118,8): warning C4047: 'initializing': 'void *' differs in levels of indirection from 'int' [C:\gitP\erincatto\box2d\build_x86\src\box2d.vcxproj]I have encountered this error at https://github.com/erincatto/box2d/blob/main/src/core.c#L118 and https://github.com/erincatto/box2d/blob/main/samples/main.cpp#L74.
#ifdef B2_PLATFORM_WINDOWS
void* ptr = _aligned_malloc( size32, B2_ALIGNMENT );
#elif defined( B2_PLATFORM_ANDROID )
....
#else
void* ptr = aligned_alloc( B2_ALIGNMENT, size32 ); // error c2220
#endifThe compiler somehow is entering into the else block, but MSVC does not supporting aligned_alloc but they have a _aligned_malloc instead. For more details, refer to the official documentation: aligned-malloc.
After I have applied this msvc_suport.patch, the build was successful, but it introduced a new issue when running test.exe. Although the test runs successfully, the exit code is incorrect. This suggests that the patch I used is likely not the correct solution."
Steps to reproduce:
- Open x86 native tools command prompt for vs2022
- git clone https://github.com/erincatto/box2d.git
- cd erincatto/box2d
- mkdir build_x86
- cd build_x86
- set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=x86 -arch=x86
- cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 .. 2>&1
- msbuild /m /p:Platform=Win32 /p:Configuration=Release box2d.sln /t:Rebuild 2>&1
- .\bin\Release\test.exe 2>&1
Build log: box2d.log
