agrep icon indicating copy to clipboard operation
agrep copied to clipboard

Make errors — MacOS Catalina, v10.15.7

Open EDePasquale opened this issue 3 years ago • 5 comments

A sequence of errors occurred during installation when calling the 'make' command. In general, most of them seem to be related to implicit declarations, examples:

  • newmgrep.c:980:61: error: implicit declaration of function 'eval_tree' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
  • recursiv.c:118:3: error: implicitly declaring library function 'strcpy' with type 'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
  • bitap.c:106:11: error: implicit declaration of function 're' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return re(fd, M, D); /* SUN: need to find a even point */

To correct this for my machine, I modified the files to either remove or move the if blocks beginning with 'ifdef_WIN32', though there is likely a better solution that doesn't affect other non-Windows operating systems. To make it successfully build on my machine I changed the following:

  • asearch.c - Comment out 'ifdef_WIN32' on line 26 and 'endif' on line 30
  • asearch1.c - Comment out 'ifdef_WIN32' on line 23 and 'endif' on line 26
  • agrep.c - Moved 'endif' up to like 225, effectively removing the declarations outside of the if block
  • bitap.c - Moved 'endif' up to like 68, effectively removing the declarations outside of the if block
  • main.c - Comment out 'ifdef_WIN32' on line 23 and 'endif' on line 25
  • parse.c - Comment out 'ifdef_WIN32' on line 7 and 'endif' on line 10
  • preproce.c - Comment out 'ifdef_WIN32' on line 45 and 'endif' on line 51
  • recursiv.c - Moved 'int exec();' outside of if block and added 'include <stdlib.h>' near top of file
  • sgrep.c - Comment out 'ifdef_WIN32' on line 126 and 'endif' on line 136
  • newmgrep.c - Comment out 'ifdef_WIN32' on line 122 and 'endif' on line 127
  • utilite.c - Moved 'include <string.h>' outside of if block and added 'include <stdlib.h>' near top of file
  • agrephlp.c - Moved 'endif' up to like 13, effectively removing the declarations outside of the if block

I may have missed a change or 2 while writing this issue, but these same actions can be used to correct other similar errors.

EDePasquale avatar Feb 11 '21 19:02 EDePasquale

thanks for reporting. I have not compiled it on/for Mac. Perhaps you can file a regular pull request, please, so that someone else can pull your request and try that. I am very sorry, that I cannot test it at the moment.

Wikinaut avatar Feb 11 '21 20:02 Wikinaut

It's easier to change the Makefile:

-CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) +CFLAGS = $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) -Wno-implicit-function-declaration

However, I'm not sure how to ifdef that so it only happens on the mac, and turning off that warning seems like a bad idea overall.

adamshostack avatar Dec 12 '21 20:12 adamshostack

I am using @EDePasquale's changes to run agrep on macOS Monterey and Red Hat Enterprise Linux Server Version 7.7 (Maipo). I'm happy to create a pull request but don't want to overreach. @Wikinaut which option do you prefer I use here: Screen Shot 2022-04-21 at 11 43 31

petervangalen avatar Apr 21 '22 15:04 petervangalen

Of course, you can issue a pull request, perhaps best in form of a well-named branch.

Wikinaut avatar Apr 22 '22 12:04 Wikinaut

I have not compiled it on/for Mac.

I am very sorry, that I cannot test it at the moment.

You don't need a Mac to verify the problem or its fix. You can add -Werror=implicit-function-declaration to CFLAGS to test it on any OS with any version of clang (and maybe gcc; I don't know). If you use LLVM.org clang 16 or later, that is even the default behavior (as it is for Apple clang 12 or later).

It's easier to change the Makefile:

-CFLAGS		= $(MYDEFINEFLAGS) $(SUBDIRCFLAGS)
+CFLAGS		= $(MYDEFINEFLAGS) $(SUBDIRCFLAGS) -Wno-implicit-function-declaration

However, I'm not sure how to ifdef that so it only happens on the mac, and turning off that warning seems like a bad idea overall.

Right, don't disable the error. Apple and LLVM.org have made it an error in their respective clangs for a reason. It needs to be fixed properly. Much more information at https://trac.macports.org/wiki/WimplicitFunctionDeclaration.

ryandesign avatar Aug 31 '23 21:08 ryandesign