-
-
Notifications
You must be signed in to change notification settings - Fork 199
Closed
Labels
Description
Description
When trying to build the project from source, it fails with the following error:
error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]This seems to be caused because glibc contains its own definition of asprintf which has the warn_unused_result attribute.
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 asprint
0000000000407650 g DF .text 00000000000000b8 Base asprintf
0000000000407510 g DF .text 000000000000013c Base vasprintfFor 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 errors
make[2]: *** [CMakeFiles/headsetcontrol.dir/build.make:76: CMakeFiles/headsetcontrol.dir/src/main.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:149: CMakeFiles/headsetcontrol.dir/all] Error 2
make: *** [Makefile:146: all] Error 2Here are some environment details:
$ uname -a
Linux kuro 6.7.11 #1-NixOS SMP PREEMPT_DYNAMIC Tue Mar 26 22:22:50 UTC 2024 x86_64 GNU/Linux
$ cmake --version
cmake version 3.28.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ make --version
GNU Make 4.4.1
Built for x86_64-pc-linux-gnu
Copyright (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 --version
gcc (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.On which OS does the problem happen?
Linux
Reactions are currently unavailable