pika icon indicating copy to clipboard operation
pika copied to clipboard

Build breaks on FreeBSD: ld: error: undefined symbol: environ

Open yurivict opened this issue 1 year ago • 3 comments

ld: error: undefined symbol: environ
>>> referenced by unity_0_cxx.cxx
>>>               libs/pika/init_runtime/CMakeFiles/pika_init_runtime.dir/Unity/unity_0_cxx.cxx.o:(pika::init(std::__1::function<int (pika::program_options::variables_map&)>, int, char const* const*, pika::init_params const&))
>>> referenced by unity_0_cxx.cxx
>>>               libs/pika/init_runtime/CMakeFiles/pika_init_runtime.dir/Unity/unity_0_cxx.cxx.o:(pika::init(std::__1::function<int (int, char**)>, int, char const* const*, pika::init_params const&))
>>> referenced by unity_0_cxx.cxx
>>>               libs/pika/init_runtime/CMakeFiles/pika_init_runtime.dir/Unity/unity_0_cxx.cxx.o:(pika::init(std::__1::function<int ()>, int, char const* const*, pika::init_params const&))
>>> referenced 5 more times

Version: 0.14.0 FreeBSD 13.1

yurivict avatar Apr 10 '23 01:04 yurivict

In other projects this was worked around like this:

-extern char** environ;
+//extern char** environ; // this is broken on FreeBSD, see https://reviews.freebsd.org/D30842
+#include <dlfcn.h>
+static char*** environ_ptr = (char***)dlsym(RTLD_DEFAULT, "environ"); // workaround for the above

and then

-        execve (argv[0], (char**) argv, environ);
+        execve (argv[0], (char**) argv, *environ_ptr);

yurivict avatar Apr 10 '23 02:04 yurivict

Thanks @yurivict.

Do you know if this is broken temporarily or "permanently" (meaning there is no plan to fix it so that the old code still works)? Do you know if this needs to be done conditionally or can the dlsym version always be used? Would be willing to provide a PR to fix this?

msimberg avatar Apr 11 '23 08:04 msimberg

The 'environ' bug is there semi-permanently. People suggested several patches but they were rejected for some reasons.

AFAIK the dlsym approach should always work.

yurivict avatar Apr 11 '23 09:04 yurivict