Skip to content

build: Fix implicit declaration of function errors

Ryan Schmidt requested to merge ryandesign/glib:implicit into main

This MR fixes a number of implicit function declaration errors in various meson tests by including the necessary system headers.

By fixing this, certain system capabilities can now be correctly detected even if implicit declaration of functions is considered an error (which it is if you add -Werror=implicit-function-declaration to CFLAGS or if you use a compiler where that behavior is the default, such as the version of clang in included with Apple Xcode 12 or later).

The errors fixed are:

build/meson-private/tmpmz1iqemr/testfile.c:17:5: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
    exit(1);
    ^
build/meson-private/tmpmz1iqemr/testfile.c:17:5: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
1 error generated.

Could not compile test file build/meson-private/tmpmz1iqemr/testfile.c: 1

Checking if "C99 vsnprintf" runs: DID NOT COMPILE
build/meson-private/tmpu8z21km4/testfile.c:15:5: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
    exit(1);
    ^
build/meson-private/tmpu8z21km4/testfile.c:15:5: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
1 error generated.

Could not compile test file build/meson-private/tmpu8z21km4/testfile.c: 1

Checking if "C99 snprintf" runs: DID NOT COMPILE
build/meson-private/tmp2dhxiq8z/testfile.c:10:7: error: implicitly declaring library function 'strcmp' with type 'int (const char *, const char *)' [-Werror,-Wimplicit-function-declaration]
  if (strcmp ("2 3 1", buffer) == 0)
      ^
build/meson-private/tmp2dhxiq8z/testfile.c:10:7: note: include the header <string.h> or explicitly provide a declaration for 'strcmp'
build/meson-private/tmp2dhxiq8z/testfile.c:11:5: error: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Werror,-Wimplicit-function-declaration]
    exit (0);
    ^
build/meson-private/tmp2dhxiq8z/testfile.c:11:5: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
3 warnings and 2 errors generated.

Could not compile test file build/meson-private/tmp2dhxiq8z/testfile.c: 1

Checking if "Unix98 printf positional parameters" runs: DID NOT COMPILE
build/meson-private/tmp4zh4jodf/testfile.c:26:11: error: implicit declaration of function 'read' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      if (read (fd, result, BUFSIZE) <= 0)
          ^
build/meson-private/tmp4zh4jodf/testfile.c:26:11: note: did you mean 'fread'?
/usr/include/stdio.h:158:9: note: 'fread' declared here
size_t   fread(void * __restrict __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream);
         ^
1 error generated.

Could not compile test file build/meson-private/tmp4zh4jodf/testfile.c: 1

Checking if "/proc/self/cmdline" runs: DID NOT COMPILE

Merge request reports