NopeCharon opened a new pull request, #813:
URL: https://github.com/apache/logging-log4cxx/pull/813
Fixes #366
## Problem
APR implements `apr_dso_load()` and related functions with `dlopen()`,
`dlsym()`, `dlclose()` and `dlerror()`. When Log4cxx links the static
`libapr-1.a` (`APR_STATIC=ON` or `BUILD_SHARED_LIBS=OFF`) on a system that is
not Windows, `FindAPR.cmake` adds only `pthread` to `APR_SYSTEM_LIBS`. In glibc
older than 2.34 (for example Ubuntu 18.04 and 20.04), these functions are in
`libdl`, so the build fails when the first test executable is linked:
```
/usr/bin/ld: ../../main/cpp/liblog4cxx.so.16.0.0: undefined reference to
`dlopen'
/usr/bin/ld: ../../main/cpp/liblog4cxx.so.16.0.0: undefined reference to
`dlclose'
/usr/bin/ld: ../../main/cpp/liblog4cxx.so.16.0.0: undefined reference to
`dlerror'
/usr/bin/ld: ../../main/cpp/liblog4cxx.so.16.0.0: undefined reference to
`dlsym'
```
## Fix
Add `${CMAKE_DL_LIBS}` to `APR_SYSTEM_LIBS` in each static, non-Windows
branch of `FindAPR.cmake`. CMake sets this variable to the library that
provides `dlopen()` on the target platform. Where `dlopen()` is part of the C
library (glibc 2.34 and later, macOS and Windows), the variable is empty, so
the change has no effect there.
`APR_SYSTEM_LIBS` is a private link dependency of `log4cxx`, so a static
Log4cxx build also exports `dl` (as `$<LINK_ONLY:dl>`) to applications that
link Log4cxx.
## Testing
I tested in an Ubuntu 20.04 container (glibc 2.31, GCC 9). APR 1.7.5 and
APR-Util 1.6.3 were built from source and installed to a separate prefix, as
described in the issue:
- On `master`, `cmake -DAPR_STATIC=yes -DAPU_STATIC=yes
-DCMAKE_PREFIX_PATH=<prefix>` followed by a build fails with the errors above.
- With this change, the full build succeeds, `liblog4cxx.so` lists
`libdl.so.2` as `NEEDED`, and the full `ctest` suite passes (70/70).
- A static Log4cxx build (`BUILD_SHARED_LIBS=OFF`, CMake 3.31) installs, and
`src/examples/cpp/MyApp` builds against the installed package. Its link line
ends with `libapr-1.a -lpthread -ldl`, and the program runs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]