Skip to content

Instantly share code, notes, and snippets.

@zao
Created August 3, 2017 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zao/56e15d9cad20fd4bb48b8f1ff9d29601 to your computer and use it in GitHub Desktop.
Save zao/56e15d9cad20fd4bb48b8f1ff9d29601 to your computer and use it in GitHub Desktop.
$ cat so.cc
extern char** environ;
#include <iostream>
void f() {
for (size_t i = 0; environ[i]; ++i) {
std::cerr << environ[i] << std::endl;
}
}
$ clang++ -shared -o so.so so.cc -fPIC
$ clang++ -shared -o so.so so.cc -fPIC -Wl,-z,defs
/tmp/so-693756.o: In function `f()':
so.cc:(.text+0x13): undefined reference to `environ'
so.cc:(.text+0x33): undefined reference to `environ'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment