23 December 2010

getopt.h:195: error: redefinition of 'struct option'

While working with Gnulib recently I kept running into problems with its getopt-gnu module:

In file included from ../../esio/gnulib/argp.h:24:0,
                 from ../../esio/apps/esio_bench.c:7:
../gnulib/getopt.h:195:8: error: redefinition of ‘struct option’
/usr/include/getopt.h:106:8: note: originally defined here
../gnulib/getopt.h:242:12: error: conflicting types for ‘getopt_long’
/usr/include/getopt.h:175:12: note: previous declaration of ‘getopt_long’ was here
../gnulib/getopt.h:246:12: error: conflicting types for ‘getopt_long_only’
/usr/include/getopt.h:179:12: note: previous declaration of ‘getopt_long_only’ was here
make[2]: *** [esio_bench.o] Error 1
which looked suspiciously like someone else's problem but couldn't be resolved by a simple make distclean.

Turns out that I failed to include the required

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

at the top of my source file. Oops. This detail is obvious in hindsight but slightly difficult to dig out of the relevant section of the gnulib manual.

No comments:

Subscribe Subscribe to The Return of Agent Zlerich