fix: glog linking error when libunwind is present#60
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes linking errors that occur when glog is built on systems with libunwind installed. When libunwind is present, glog automatically links against it for stack unwinding support, but the INTERFACE_LINK_LIBRARIES property was not being set, causing undefined reference errors during static library linking.
Changes:
- Added dynamic detection of libunwind availability using CMake's find_library
- Conditionally adds libunwind to glog's interface link libraries when present
- Ensures portability across systems with and without libunwind
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| set_property(TARGET glog | ||
| APPEND | ||
| PROPERTY INTERFACE_LINK_LIBRARIES unwind) | ||
| endif() | ||
| endmacro() |
There was a problem hiding this comment.
Consider using the variable ${LIBUNWIND_LIBRARY} instead of the bare library name "unwind". Since find_library stores the full path to the library in LIBUNWIND_LIBRARY, using ${LIBUNWIND_LIBRARY} ensures the exact library that was detected is linked. Alternatively, for better consistency with the codebase style at lines 474, 592, and 840, consider using target_link_libraries(glog INTERFACE ${LIBUNWIND_LIBRARY}) instead of set_property.
| set_property(TARGET glog | |
| APPEND | |
| PROPERTY INTERFACE_LINK_LIBRARIES unwind) | |
| endif() | |
| endmacro() | |
| target_link_libraries(glog INTERFACE ${LIBUNWIND_LIBRARY}) | |
| endif() | |
| endmacro() | |
| endmacro() |
When glog is built on systems with libunwind installed, it automatically detects and links against libunwind for stack unwinding support. However, the INTERFACE_LINK_LIBRARIES property was not set, causing undefined reference errors (e.g., _Ux86_64_getcontext) when linking static libraries. This change dynamically detects libunwind availability and adds it to glog's link interface only when present, ensuring portability across different build environments.
|
Seems to be broken by main branch... |
Thanks to find this problem! It's caused by a random number case, we will fix this. cc @lxy-9602 |
Purpose
When glog is built on systems with libunwind installed, it automatically detects and links against libunwind for stack unwinding support. However, the
INTERFACE_LINK_LIBRARIESproperty was not set, causing undefined reference errors when linking static libraries:This change dynamically detects libunwind availability and adds it to glog's link interface only when present, ensuring portability across different build environments.
According to the docs of glog, libunwind is recommended.
Tests
For system without libunwind:
For system with libunwind:
API and Format
Documentation