Page MenuHome GnuPG

OS X 10.11 and error: use of undeclared identifier 'getenv'
Closed, ResolvedPublic

Description

Building gpgme-1.14.0 on OS X 10.11. From MacPorts Issue 60930 (https://trac.macports.org/ticket/60930):

998	:info:build warning: unknown warning option '-Wsuggest-override'; did you mean '-Wshift-overflow'? [-Wunknown-warning-option]
999	:info:build warning: unknown warning option '-Wzero-as-null-pointer-constant'; did you mean '-Wint-to-void-pointer-cast'? [-Wunknown-warning-option]
1000	:info:build editinteractor.cpp:181:29: error: use of undeclared identifier 'getenv'
1001	:info:build     const char *debug_env = getenv("GPGMEPP_INTERACTOR_DEBUG");
1002	:info:build                             ^
1003	:info:build 2 warnings and 1 error generated.
1004	:info:build make[3]: *** [editinteractor.lo] Error 1
1005	:info:build make[3]: *** Waiting for unfinished jobs....
1006	:info:build 2 warnings generated.

Details

External Link
https://trac.macports.org/ticket/60930
Version
1.14.0

Revisions and Commits

Event Timeline

JW updated the task description. (Show Details)

According to OS X 10.9 man pages for getenv(3) (10.9 is what I have available), the source file editinteractor.cpp should include <stdlib.h>. Since its a c++ source file, I believe the include of interest is <cstdlib>. The man page also says the link library is -lc.

GETENV(3)                BSD Library Functions Manual                GETENV(3)

NAME
     getenv, putenv, setenv, unsetenv -- environment variable functions

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <stdlib.h>

     char *
     getenv(const char *name);

     int
     putenv(char *string);

     int
     setenv(const char *name, const char *value, int overwrite);

     int
     setenv(const char *name, const char *value, int overwrite);

     int
     unsetenv(const char *name);

     ...

Thanks for your report.

I'm not sure if including is required or not. Minimum patch would be:

diff --git a/lang/cpp/src/editinteractor.cpp b/lang/cpp/src/editinteractor.cpp
index 36d1be63..98b727a7 100644
--- a/lang/cpp/src/editinteractor.cpp
+++ b/lang/cpp/src/editinteractor.cpp
@@ -178,7 +178,7 @@ EditInteractor::Private::Private(EditInteractor *qq)
       error(),
       debug(nullptr)
 {
-    const char *debug_env = getenv("GPGMEPP_INTERACTOR_DEBUG");
+    const char *debug_env = std::getenv("GPGMEPP_INTERACTOR_DEBUG");
     if (!debug_env) {
         return;
     }

Thanks, I've applied this with an explicit include to <cstdlib> it was not required on Linux and Windows but I think it's better not to rely on internal libc++ include chains.

I didn't know that getenv was not on MacOS so apologies for breaking the build. Long term we should get our CI back to build for multiple platforms but currently we don't have the manpower to maintain that.

aheinecke claimed this task.