Build gRPC shared against abseil static: undefined reference to nan@@GLIBC_2.2.5 in `charconv.cc` (`absl_strings`) on Linux
- Lenguaje dominante
- C++
- Estrellas
- 18.1k
- Forks
- 3.2k
- Merge medio
- 20 h 36 min
- PR fusionados (30 d)
- 1
Descripción
**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>
...
```
Guía de contribución
Línea de trabajo
El problema está en absl/strings/charconv.cc, que utiliza `nan` de libm. El CMakeLists.txt de la biblioteca absl_strings debe enlazar con libm cuando se compile estáticamente. Empieza examinando absl/strings/CMakeLists.txt y la macro absl_cc_library. Entiende cómo se propaga LINKOPTS. Es probable que la corrección consista en añadir `-lm` a las opciones de enlace del destino strings. Prueba compilando abseil estáticamente y después compilando gRPC como biblioteca compartida contra él para verificar que se resuelve la referencia indefinida.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- cmake, cpp
- Área
- build-system
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 40/100