C99 compile - static_assert failure #764

Closed
opened 2025-12-11 09:29:36 -06:00 by cscd98 · 5 comments
cscd98 commented 2025-12-11 09:29:36 -06:00 (Migrated from github.com)

With C standard of C99 static_assert is no longer available causing a compile failure:

github.com/libusb/hidapi@a7587175f3/windows/hidapi_descriptor_reconstruct.h (L133)

With C standard of C99 static_assert is no longer available causing a compile failure: https://github.com/libusb/hidapi/blob/a7587175f35ddcbdfb1ce5a1e4dd7a268699ba7f/windows/hidapi_descriptor_reconstruct.h#L133
mcuee commented 2025-12-19 19:15:11 -06:00 (Migrated from github.com)

What is the compiler used to trigger this issue?

Take note we only support MSYS2 GCC/clang and MSVC under Windows.

What is the compiler used to trigger this issue? Take note we only support MSYS2 GCC/clang and MSVC under Windows.
cscd98 commented 2025-12-20 03:02:21 -06:00 (Migrated from github.com)

Hi, it would had been the latest msys2 release on Windows.

Hi, it would had been the latest msys2 release on Windows.
mcuee commented 2025-12-20 05:57:04 -06:00 (Migrated from github.com)

I just tried latest MSYS2 mingw64 toolchain under Windows 11 and there is no issue to build latest hidapi git.

MINGW64 /c/work/libusb/hidapi
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-15.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-mingw-wildcard --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev8, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-libstdcxx-zoneinfo=yes --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.2.0 (Rev8, Built by MSYS2 project)

$ cat build_cmake_mingw64_1.sh
cmake -B buildmingw64 -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DCMAKE_INSTALL_PREFIX=buildmingw64 -DHIDAPI_BUILD_HIDTEST=ON
cmake --build buildmingw64 --target install

$ sh build_cmake_mingw64_1.sh
-- Building for: Ninja
-- The C compiler identification is GNU 15.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- hidapi: v0.16.0
-- Building hidtest
-- Configuring done (0.8s)
-- Generating done (0.0s)
-- Build files have been written to: C:/work/libusb/hidapi/buildmingw64
[10/11] Install the project...-- Install configuration: "RelWithDebInfo"
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/libhidapi.dll.a
-- Installing: C:/work/libusb/hidapi/buildmingw64/bin/libhidapi.dll
-- Installing: C:/work/libusb/hidapi/buildmingw64/include/hidapi/hidapi.h
-- Installing: C:/work/libusb/hidapi/buildmingw64/include/hidapi/hidapi_winapi.h
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/pkgconfig/hidapi.pc
-- Installing: C:/work/libusb/hidapi/buildmingw64/bin/pp_data_dump.exe
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/libhidapi.cmake
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/libhidapi-relwithdebinfo.cmake
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/hidapi-config-version.cmake
-- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/hidapi-config.cmake
-- Installing: C:/work/libusb/hidapi/buildmingw64/bin/hidtest.exe
I just tried latest MSYS2 mingw64 toolchain under Windows 11 and there is no issue to build latest hidapi git. ``` MINGW64 /c/work/libusb/hidapi $ gcc -v Using built-in specs. COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../gcc-15.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-mingw-wildcard --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev8, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-libstdcxx-zoneinfo=yes --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++ Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 15.2.0 (Rev8, Built by MSYS2 project) $ cat build_cmake_mingw64_1.sh cmake -B buildmingw64 -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHIDAPI_WITH_TESTS=ON -DHIDAPI_BUILD_PP_DATA_DUMP=ON -DCMAKE_INSTALL_PREFIX=buildmingw64 -DHIDAPI_BUILD_HIDTEST=ON cmake --build buildmingw64 --target install $ sh build_cmake_mingw64_1.sh -- Building for: Ninja -- The C compiler identification is GNU 15.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- hidapi: v0.16.0 -- Building hidtest -- Configuring done (0.8s) -- Generating done (0.0s) -- Build files have been written to: C:/work/libusb/hidapi/buildmingw64 [10/11] Install the project...-- Install configuration: "RelWithDebInfo" -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/libhidapi.dll.a -- Installing: C:/work/libusb/hidapi/buildmingw64/bin/libhidapi.dll -- Installing: C:/work/libusb/hidapi/buildmingw64/include/hidapi/hidapi.h -- Installing: C:/work/libusb/hidapi/buildmingw64/include/hidapi/hidapi_winapi.h -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/pkgconfig/hidapi.pc -- Installing: C:/work/libusb/hidapi/buildmingw64/bin/pp_data_dump.exe -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/libhidapi.cmake -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/libhidapi-relwithdebinfo.cmake -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/hidapi-config-version.cmake -- Installing: C:/work/libusb/hidapi/buildmingw64/lib/cmake/hidapi/hidapi-config.cmake -- Installing: C:/work/libusb/hidapi/buildmingw64/bin/hidtest.exe ```
cscd98 commented 2025-12-20 07:28:43 -06:00 (Migrated from github.com)

It only occurs when setting the c standard to 99.

set(CMAKE_C_STANDARD 99)

It only occurs when setting the c standard to 99. set(CMAKE_C_STANDARD 99)
Youw commented 2025-12-20 13:45:41 -06:00 (Migrated from github.com)

If this is the only breaking code for C11, I guess we could have a condition on C standard for the compilation.
But I'd like to know what forces you to use C99 to compile HIDAPI?

If this is the only breaking code for C11, I guess we could have a condition on C standard for the compilation. But I'd like to know what forces you to use C99 to compile HIDAPI?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#764
No description provided.