hudkit icon indicating copy to clipboard operation
hudkit copied to clipboard

Compiling with Nix toolchain

Open vrinek opened this issue 3 years ago • 2 comments

Hello, I've been trying to get hudkit compiled on NixOS using the nix toolchain.

More specifically, I've tried the following with no success:

❯ nix-shell --packages pkg-config gtk3 webkitgtk --run make
gcc -std=c11 main.c -o hudkit `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`
main.c: In function ‘main’:
main.c:450:32: warning: implicit declaration of function ‘strtok_r’; did you mean ‘strtok’? [-Wimplicit-function-declaration]
  450 |             for (char *entry = strtok_r(
      |                                ^~~~~~~~
      |                                strtok
main.c:450:32: warning: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
main.c:450:13: error: declaration of non-variable ‘strtok_r’ in ‘for’ loop initial declaration
  450 |             for (char *entry = strtok_r(
      |             ^~~
main.c:453:27: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  453 |                     entry = strtok_r(NULL, ",", &strtok_savepoint)) {
      |                           ^
main.c:711:12: error: variable ‘usr1_action’ has initializer but incomplete type
  711 |     struct sigaction usr1_action = {
      |            ^~~~~~~~~
main.c:712:10: error: ‘struct sigaction’ has no member named ‘sa_handler’
  712 |         .sa_handler = on_signal_sigusr1
      |          ^~~~~~~~~~
main.c:712:23: warning: excess elements in struct initializer
  712 |         .sa_handler = on_signal_sigusr1
      |                       ^~~~~~~~~~~~~~~~~
main.c:712:23: note: (near initialization for ‘usr1_action’)
main.c:711:22: error: storage size of ‘usr1_action’ isn’t known
  711 |     struct sigaction usr1_action = {
      |                      ^~~~~~~~~~~
main.c:714:5: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]
  714 |     sigaction(SIGUSR1, &usr1_action, NULL);
      |     ^~~~~~~~~
make: *** [makefile:2: hudkit] Error 1

Do you have any tips on how I might get through this?

vrinek avatar Jan 07 '22 10:01 vrinek

Thanks for reporting. :sparkles:

I read up a little bit. Both strtok_r and sigaction are POSIX extensions, which would explain these errors. GCC on Nix must have them available too, but some compilers in some environments apparently want to be told specifically to use them. I've added such annotations in commit https://github.com/anko/hudkit/commit/61e0077d457b6b398ca21bff13b5a0dcbb6548ff. Try now and let me know how it goes.

anko avatar Jan 09 '22 02:01 anko

Thank you for the quick response.

I tried both the latest master and 61e0077 and got mostly the same errors, plus some more:

❯ nix-shell --packages pkg-config gtk3 webkitgtk --run make
gcc -std=c11 main.c -o hudkit `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`
In file included from /nix/store/ch44wa8qqss0dm04lnvf5n7mfh23kmrv-glibc-2.31-74-dev/include/bits/libc-header-start.h:33,
                 from /nix/store/ch44wa8qqss0dm04lnvf5n7mfh23kmrv-glibc-2.31-74-dev/include/limits.h:26,
                 from /nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/limits.h:194,
                 from /nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/syslimits.h:7,
                 from /nix/store/fvf3qjqa5qpcjjkq37pb6ypnk1mzhf5h-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/limits.h:34,
                 from /nix/store/ai5054xzilz0q285c0ldabmkvhyyl6yq-glib-2.64.6/lib/glib-2.0/include/glibconfig.h:11,
                 from /nix/store/cajm8vsbc7726i955nbdz707ij62j9hz-glib-2.64.6-dev/include/glib-2.0/glib/gtypes.h:32,
                 from /nix/store/cajm8vsbc7726i955nbdz707ij62j9hz-glib-2.64.6-dev/include/glib-2.0/glib/galloca.h:32,
                 from /nix/store/cajm8vsbc7726i955nbdz707ij62j9hz-glib-2.64.6-dev/include/glib-2.0/glib.h:30,
                 from /nix/store/cj5dsrxs0pnz3kahpdqlkvj24ir0255z-gtk+3-3.24.21-dev/include/gtk-3.0/gdk/gdkconfig.h:8,
                 from /nix/store/cj5dsrxs0pnz3kahpdqlkvj24ir0255z-gtk+3-3.24.21-dev/include/gtk-3.0/gdk/gdk.h:30,
                 from /nix/store/cj5dsrxs0pnz3kahpdqlkvj24ir0255z-gtk+3-3.24.21-dev/include/gtk-3.0/gtk/gtk.h:30,
                 from main.c:4:
/nix/store/ch44wa8qqss0dm04lnvf5n7mfh23kmrv-glibc-2.31-74-dev/include/features.h:314:53: error: operator '&&' has no right operand
  314 |      || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1) \
      |                                                     ^~
/nix/store/ch44wa8qqss0dm04lnvf5n7mfh23kmrv-glibc-2.31-74-dev/include/features.h:319:48: error: operator '&&' has no right operand
  319 | #if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || defined _XOPEN_SOURCE
      |                                                ^~
main.c: In function ‘main’:
main.c:452:32: warning: implicit declaration of function ‘strtok_r’; did you mean ‘strtok’? [-Wimplicit-function-declaration]
  452 |             for (char *entry = strtok_r(
      |                                ^~~~~~~~
      |                                strtok
main.c:452:32: warning: initialization of ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
main.c:452:13: error: declaration of non-variable ‘strtok_r’ in ‘for’ loop initial declaration
  452 |             for (char *entry = strtok_r(
      |             ^~~
main.c:455:27: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  455 |                     entry = strtok_r(NULL, ",", &strtok_savepoint)) {
      |                           ^
main.c:713:12: error: variable ‘usr1_action’ has initializer but incomplete type
  713 |     struct sigaction usr1_action = {
      |            ^~~~~~~~~
main.c:714:10: error: ‘struct sigaction’ has no member named ‘sa_handler’
  714 |         .sa_handler = on_signal_sigusr1
      |          ^~~~~~~~~~
main.c:714:23: warning: excess elements in struct initializer
  714 |         .sa_handler = on_signal_sigusr1
      |                       ^~~~~~~~~~~~~~~~~
main.c:714:23: note: (near initialization for ‘usr1_action’)
main.c:713:22: error: storage size of ‘usr1_action’ isn’t known
  713 |     struct sigaction usr1_action = {
      |                      ^~~~~~~~~~~
main.c:716:5: warning: implicit declaration of function ‘sigaction’ [-Wimplicit-function-declaration]
  716 |     sigaction(SIGUSR1, &usr1_action, NULL);
      |     ^~~~~~~~~
make: *** [makefile:2: hudkit] Error 1

I'll try to find some info on what look like nix-specific issues at the top of the output.

vrinek avatar Jan 11 '22 13:01 vrinek

@vrinek anything new?

~~If you aren't willing to work on this (for whatever reason) I can try and package for nixpkgs myself~~

UPDATE: Hudkit compiles fine now?

nferhat avatar Mar 29 '23 16:03 nferhat

I haven't tried this since, well, last year. I'll close this issue, and feel free to reopen it if still relevant.

vrinek avatar May 06 '23 16:05 vrinek