abseil / abseil/abseil-cpp

Build gRPC shared against abseil static: undefined reference to nan@@GLIBC_2.2.5 in `charconv.cc` (`absl_strings`) on Linux

未关闭
#1,100 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
C++
星标
18.1k
派生
3.2k
平均合并
20 小时 36 分钟
30 天内合并 PR
1

描述

**Describe the bug**

Undefined reference to `nan` in `charconv.cc` (`absl_strings`) while building `gRPC` shared against `abseil` static on Linux with gcc-10:

```
[ 98%] Linking CXX shared library ../lib/libgrpc++.so
/usr/bin/ld: /home/conan/w/BuildSingleReference/.conan/data/abseil/20211102.0/_/_/package/b173bbda18164d49a449ffadc1c9e817f49e819d/lib/libabsl_strings.a(charconv.cc.o): undefined reference to symbol 'nan@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
```

**Steps to reproduce the bug**

- Linux and C++ lib without nan implementation in `std::` namespace I guess.
- Build abseil static
- Build gRPC shared

**What version of Abseil are you using?**

20211102.0

**What operating system and version are you using**

Some linux distribution, ubuntu 20 I guess (a docker of a CI I don't control so sorry not much information).

**What compiler and version are you using?**

gcc-10

**What build system are you using?**

CMake

**Additional context**

I think that `absl_strings` may depend on libm instead of libstdc++ only, due to https://github.com/abseil/abseil-cpp/blob/fbbb5865a562c9a9167d71c1cf56b82025a8f065/absl/strings/charconv.cc#L86-L91

So I guess it's sufficient to link directly to libm in case of, and add this in CMakeLists of absl_strings, so that libm is properly propagated in CMake imported target if static:

```cmake
find_library(LIBM m)

absl_cc_library(
NAME
strings
...
LINKOPTS
$<$:-lm>
...
```

贡献指南

打开贡献指南

调研方向

The issue is in absl/strings/charconv.cc, which uses `nan` from libm. The CMakeLists.txt for the absl_strings library needs to link to libm when built statically. Start by examining absl/strings/CMakeLists.txt and the absl_cc_library macro. Understand how LINKOPTS are propagated. The fix likely involves adding `-lm` to the link options for the strings target. Test by building abseil statically and then building gRPC shared against it to verify the undefined reference is resolved.

由索引模型根据 Issue 内容生成。

评估

技术栈
cmake, cpp
领域
build-system
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
40/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。