ideal / dhex

dhex (http://www.dettus.net/dhex/) with some bug fixes
1 stars 0 forks source link

[patch] GCC 14.x: Build fails with `error: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]`. #1

Open dreirund opened 2 weeks ago

dreirund commented 2 weeks ago

A patch is given in this comment.


Ahoj,

with GCC 14.x, build fails for me with error: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]:

gcc buffers.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99
gcc configfile.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99
[...]
input.c: In function ‘getkey’:
input.c:72:33: error: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
   72 |                                 usleep(1);
      |                                 ^~~~~~
      |                                 sleep
make: *** [Makefile:40: input.o] Error 1
[...]

Full make output (with a lot of warnings):

gcc buffers.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
gcc configfile.c -c -I. -I/usr/include  -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
configfile.c: In function ‘readconfigfile’:
configfile.c:193:58: warning: pointer targets in passing argument 2 of ‘getcolors’ differ in signedness [-Wpointer-sign]
  193 |                                         getcolors(output,line);
      |                                                          ^~~~
      |                                                          |
      |                                                          unsigned char *
configfile.c:77:37: note: expected ‘char *’ but argument is of type ‘unsigned char *’
   77 | int getcolors(tOutput* output,char* line)
      |                               ~~~~~~^~~~
configfile.c:194:94: warning: pointer targets in passing argument 2 of ‘configkeytab’ differ in signedness [-Wpointer-sign]
  194 |                                         keyboardcnt+=(configkeytab((tKeyTab*)output->pKeyTab,line)==0);
      |                                                                                              ^~~~
      |                                                                                              |
      |                                                                                              unsigned char *
In file included from configfile.c:9:
input.h:43:41: note: expected ‘char *’ but argument is of type ‘unsigned char *’
   43 | int configkeytab(tKeyTab* pKeyTab,char* line);
      |                                   ~~~~~~^~~~
gcc correlation.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
correlation.c: In function ‘find_longestmatch’:
correlation.c:30:60: warning: format ‘%lli’ expects argument of type ‘long long int’, but argument 5 has type ‘int’ [-Wformat=]
   30 |                 if (smallwin) mvwprintw(smallwin,4,1,"%18lli",0);
      |                                                       ~~~~~^  ~
      |                                                            |  |
      |                                                            |  int
      |                                                            long long int
      |                                                       %18i
correlation.c: In function ‘find_bestmatch’:
correlation.c:118:60: warning: format ‘%lli’ expects argument of type ‘long long int’, but argument 5 has type ‘int’ [-Wformat=]
  118 |                 if (smallwin) mvwprintw(smallwin,4,1,"%18lli",0);
      |                                                       ~~~~~^  ~
      |                                                            |  |
      |                                                            |  int
      |                                                            long long int
      |                                                       %18i
correlation.c: In function ‘find_mindiff’:
correlation.c:181:17: warning: variable ‘match’ set but not used [-Wunused-but-set-variable]
  181 |         tInt64  match;
      |                 ^~~~~
gcc gpl.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
gcc hexcalc.c -c -I. -I/usr/include -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
hexcalc.c: In function ‘hexcalc’:
hexcalc.c:85:95: warning: format ‘%i’ expects argument of type ‘int’, but argument 5 has type ‘tUInt64’ {aka ‘long long unsigned int’} [-Wformat=]
   85 |                                 if (x || !j)    mvwprintw(output->win,offsy+18-i,offsx+76-j,"%i",(x&1));
      |                                                                                              ~^  ~~~~~
      |                                                                                               |    |
      |                                                                                               int  tUInt64 {aka long long unsigned int}
      |                                                                                              %lli
hexcalc.c:99:85: warning: format ‘%i’ expects argument of type ‘int’, but argument 5 has type ‘tUInt64’ {aka ‘long long unsigned int’} [-Wformat=]
   99 |                         if (x || !j)    mvwprintw(output->win,offsy+19,offsx+76-j,"%i",(x&1));
      |                                                                                    ~^  ~~~~~
      |                                                                                     |    |
      |                                                                                     int  tUInt64 {aka long long unsigned int}
      |                                                                                    %lli
gcc input.c -c -I. -I/usr/include   -I/usr/local/include    -I/usr/include/ncurses  -I/usr/local/include/ncurses -O3 -Wall -std=c99  
input.c: In function ‘getkey’:
input.c:72:33: error: implicit declaration of function ‘usleep’; did you mean ‘sleep’? [-Wimplicit-function-declaration]
   72 |                                 usleep(1);
      |                                 ^~~~~~
      |                                 sleep
make: *** [Makefile:40: input.o] Error 1

Regards!

dreirund commented 2 weeks ago

A fix for the error is this patch. Note that it might be not a good fix. Also note that the many warnings also still need to be fixed.

diff -rU1 dhex.orig/input.c dhex/input.c
--- dhex.orig/input.c   2024-09-10 14:00:35.636713152 +0200
+++ dhex/input.c    2024-09-10 14:14:03.650062329 +0200
@@ -1 +1,6 @@
+// Work around "error: implicit declaration of function ‘usleep’; did you mean ‘sleep’?" error in GCC 14.x
+# if __GNUC__ >= 14
+  #define _DEFAULT_SOURCE
+#endif
+
 #include <stdio.h>