You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I remove -Werror and build the binary, everything works as expected and the asprintf linked
in the final binary is the one from your utility.h, so it's quite strange that gcc complains about it.
$ objdump -T headsetcontrol | grep asprint0000000000407650 g DF .text 00000000000000b8 Base asprintf0000000000407510 g DF .text 000000000000013c Base vasprintf
For completeness, here is the full build log:
$ nix-shell -p cmake hidapi
$ mkdir build &&cd build
$ cmake ..
$ make[ 3%] Building C object CMakeFiles/headsetcontrol.dir/src/main.c.o/home/leix/Documents/github/HeadsetControl/src/main.c: In function ‘handle_feature’:/home/leix/Documents/github/HeadsetControl/src/main.c:197:9: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 197 | asprintf(&result.message, "This headset doesn't support %s", capabilities_str[cap]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:208:13: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 208 | asprintf(&result.message, "Could not open device. Error: %ls", hid_error(*device_handle)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:229:13: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 229 | asprintf(&result.message, "Battery: %d%%", battery.level); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:247:17: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 247 | asprintf(&result.message, "Error retrieving battery status. Error: %ls", hid_error(*device_handle)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:249:17: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 249 | asprintf(&result.message, "Error retrieving battery status"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:272:13: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 272 | asprintf(&result.message, "Chat-Mix: %d", ret); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:327:9: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 327 | asprintf(&result.message, "Failed to set/request %s, because of timeout", capabilities_str[cap]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:330:9: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 330 | asprintf(&result.message, "Failed to set/request %s. HeadsetControl Error", capabilities_str[cap]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:333:9: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 333 | asprintf(&result.message, "Failed to set/request %s. Provided parameter out of boundaries", capabilities_str[cap]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:337:13: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 337 | asprintf(&result.message, "Failed to set/request %s. Error: %d: %ls", capabilities_str[cap], ret, hid_error(*device_handle)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/home/leix/Documents/github/HeadsetControl/src/main.c:339:13: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 339 | asprintf(&result.message, "Failed to set/request %s. Error: %d", capabilities_str[cap], ret); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errorsmake[2]: *** [CMakeFiles/headsetcontrol.dir/build.make:76: CMakeFiles/headsetcontrol.dir/src/main.c.o] Error 1make[1]: *** [CMakeFiles/Makefile2:149: CMakeFiles/headsetcontrol.dir/all] Error 2make: *** [Makefile:146: all] Error 2
Here are some environment details:
$ uname -aLinux kuro 6.7.11 #1-NixOS SMP PREEMPT_DYNAMIC Tue Mar 26 22:22:50 UTC 2024 x86_64 GNU/Linux
$ cmake --versioncmake version 3.28.3CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ make --versionGNU Make 4.4.1Built for x86_64-pc-linux-gnuCopyright (C) 1988-2023 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law.
$ gcc --versiongcc (GCC) 13.2.0Copyright (C) 2023 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
On which OS does the problem happen?
Linux
The text was updated successfully, but these errors were encountered:
I'm currently the maintainer of the AUR package and can confirm this issue. Arch Linux's build system contains a lot of additional compiler flags, which triggers a bunch of warning. And with -Werror, the build just fails. The current workaround is omitting the following line in the CMake file:
Also thanks for the compilation parameters @TheBill2001
I will try to fix the resulting warnings for it. But I think I also have to get rid of the -Werror in the repo, as other Distributions can then again have other compilation parameters creating warnings and leading to an error.
For the asprintf Im not sure if I should replace it by the function in the code or check the return values. Checking the return values would be the 100% "right" way, but if something like memory allocation fails the program will crash anyway.
Description
When trying to build the project from source, it fails with the following error:
This seems to be caused because glibc contains its own definition of
asprintf
which has thewarn_unused_result
attribute.If I remove
-Werror
and build the binary, everything works as expected and theasprintf
linkedin the final binary is the one from your
utility.h
, so it's quite strange thatgcc
complains about it.For completeness, here is the full build log:
Here are some environment details:
On which OS does the problem happen?
Linux
The text was updated successfully, but these errors were encountered: