Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build error on aarch64-linux-gnu: ncvalidator.c: error: ‘optind’ undeclared #2303

Closed
Alexander-Barth opened this issue Apr 25, 2022 · 1 comment

Comments

@Alexander-Barth
Copy link
Contributor

I am trying to cross-compile NetCDF 4.8.1 for the julia project but I have a compile error on aarch64-linux-gnu.

  • the version of the software with which you are encountering an issue

NetCDF 4.8.1

  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)

Cross-compilation: host: Linux x86_64 target: aarch64-linux-gnu
Compiler: aarch64-linux-gnu-gcc (GCC) 4.8.5

  • a description of the issue with the steps needed to reproduce it

NetCDF is compiled and configured in the following way:

./configure --prefix=${prefix} \
    --build=${MACHTYPE} \
    --host=${target} \
    --enable-shared \
    --disable-static \
    --disable-dap-remote-tests \
    --disable-utilities

The full error message is:

ncvalidator.c: In function ‘main’:
ncvalidator.c:2288:5: warning: implicit declaration of function ‘getopt’ [-Wimplicit-function-declaration]
     while ((i = getopt(argc, argv, "xthq")) != EOF)
     ^
ncvalidator.c:2301:14: error: ‘optind’ undeclared (first use in this function)
     if (argv[optind] == NULL) { /* input file name is mandatory */
              ^
ncvalidator.c:2301:14: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [Makefile:1322: ncvalidator.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/workspace/srcdir/netcdf-c-4.8.1/ncdump'
make[2]: *** [Makefile:1401: all-recursive] Error 1
make[2]: Leaving directory '/workspace/srcdir/netcdf-c-4.8.1/ncdump'
make[1]: *** [Makefile:729: all-recursive] Error 1
make[1]: Leaving directory '/workspace/srcdir/netcdf-c-4.8.1'
make: *** [Makefile:574: all] Error 2
Previous command exited with 2

The follow patch solves this issue:

From 86baf9cd28c20ad3589546639b44b776edef1684 Mon Sep 17 00:00:00 2001
From: Alexander Barth <barth.alexander@gmail.com>
Date: Wed, 2 Mar 2022 14:24:23 +0100
Subject: [PATCH 2/3] include getopt.h if available

---
 ncdump/ncvalidator.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/ncdump/ncvalidator.c b/ncdump/ncvalidator.c
index dead0d03..8f275b10 100644
--- a/ncdump/ncvalidator.c
+++ b/ncdump/ncvalidator.c
@@ -60,6 +60,9 @@ THIS SOFTWARE.
 */
 
 #include "config.h"
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>  /* open() */
-- 
2.25.1

In essence we include getopt.h if HAVE_GETOPT_H is defined as in ncdump/ncdump.c

DennisHeimbigner added a commit to DennisHeimbigner/netcdf-c that referenced this issue Apr 28, 2022
## Include <getopt.h> in various utilities
re: Unidata#2303
As noted, some utilities are using getopt() without including
getopt.h, so add as needed.

## Turn off run_diskless2.sh when ENABLE_PARALLEL is true
re: Unidata#2315
Ed notes that this test hangs when running parallel.  The test
is attempting to create a very large in-memory file, which is
the proximate cause. But no idea what's the underlying cause.
@DennisHeimbigner
Copy link
Collaborator

Fixed by PR #2316

@WardF WardF closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants