diff --git a/nlopt_config.h.in b/nlopt_config.h.in index 464c60b32bf7ad8648dafb562637821167cab6d3..51198510aef3dd7dd9b6f1aec19579dd9c282608 100644 --- a/nlopt_config.h.in +++ b/nlopt_config.h.in @@ -37,6 +37,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_GETOPT_H +/* Define to 1 if you have the getopt function in your standard libary. */ +#cmakedefine HAVE_GETOPT + /* Define to 1 if you have the `getpid' function. */ #cmakedefine HAVE_GETPID diff --git a/src/util/nlopt-getopt.h b/src/util/nlopt-getopt.h index 9af5298fee944dc2825d32fab0b75eca0a5c2d9c..d89e1e5f068fd2f0ce4d9a249dc508a4b3e7ed39 100644 --- a/src/util/nlopt-getopt.h +++ b/src/util/nlopt-getopt.h @@ -34,6 +34,14 @@ #ifndef NLOPT_GETOPT_H #define NLOPT_GETOPT_H +/* avoid linker conflicts if we use nlopt-getopt.c with a libc that has getopt */ +#define opterr nlopt_opterr +#define optind nlopt_optind +#define optopt nlopt_optopt +#define optreset nlopt_optreset +#define optarg nlopt_optarg +#define getopt nlopt_getopt + #ifdef __cplusplus extern "C" { #endif diff --git a/test/testopt.c b/test/testopt.c index d1f927dc70c4174dcdcffc8041038e915c76b456..eb0d9e8deda0ead3d4fe4848884b7f880dd9e08f 100644 --- a/test/testopt.c +++ b/test/testopt.c @@ -30,7 +30,7 @@ #ifdef HAVE_UNISTD_H # include #endif -#ifdef HAVE_GETOPT_H +#if defined(HAVE_GETOPT_H) && defined(HAVE_GETOPT) # include #else # include "nlopt-getopt.h"