[llvm] [flang-rt] Fix runtime/environment.cpp compilation on FreeBSD (PR #219705)
Rainer Orth via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 10:51:27 PDT 2026
https://github.com/rorth created https://github.com/llvm/llvm-project/pull/219705
`runtime/environment.cpp` doesn't compile on FreeBSD:
```
runtime/environment.cpp:115:47: error: use of undeclared identifier 'RTLD_DEFAULT'
115 | auto envpp{reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"))};
| ^~~~~~~~~~~~
```
`<dlfcn.h>` needs to be included.
Tested on `x86_64-pc-freebsd15.1` and `x86_64-pc-linux-gnu`.
>From 1bcafe6331b1102cd78194d7c028e6499cab38be Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Sat, 29 Aug 2026 19:49:10 +0200
Subject: [PATCH] [flang-rt] Fix runtime/environment.cpp compilation on FreeBSD
`runtime/environment.cpp` doesn't compile on FreeBSD:
```
runtime/environment.cpp:115:47: error: use of undeclared identifier 'RTLD_DEFAULT'
115 | auto envpp{reinterpret_cast<char ***>(dlsym(RTLD_DEFAULT, "environ"))};
| ^~~~~~~~~~~~
```
`<dlfcn.h>` needs to be included.
Tested on `x86_64-pc-freebsd15.1` and `x86_64-pc-linux-gnu`.
---
flang-rt/lib/runtime/environment.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/flang-rt/lib/runtime/environment.cpp b/flang-rt/lib/runtime/environment.cpp
index 4f3f0e46bb87d..5bbc7f2d29129 100644
--- a/flang-rt/lib/runtime/environment.cpp
+++ b/flang-rt/lib/runtime/environment.cpp
@@ -21,6 +21,8 @@
// FreeBSD has environ in crt rather than libc. Using "extern char** environ"
// in the code of a shared library makes it fail to link with -Wl,--no-undefined
// See https://reviews.freebsd.org/D30842#840642
+#include <dlfcn.h>
+#elif RT_GPU_TARGET
// GPU targets do not provide environ.
#else
extern char **environ;
More information about the llvm-commits
mailing list