Link errors in cross compilation
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- cmake, cpp
- Área
- build-system
Línea de trabajo
Reproduce el fallo utilizando el toolchain.cmake proporcionado, la versión v1.7.1 y los comandos de compilación estática. Compara la configuración de enlace estático generada y el comportamiento del enlazador con el comando -flto que funciona; la tarea estará completada cuando el test de ejemplo se enlace correctamente sin LTO para el objetivo x86_64-w64-mingw32.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
I tried to cross compile benchmark to x86_64-w64-mingw32. When I set "-DBUILD_SHARED_LIBS=ON", no error generated. When I set "-DBUILD_SHARED_LIBS=OFF", the libbenchmark could be built. But when I tried to run the test, link errors generated.
The test code:
void BM_empty(benchmark::State& state) {
for (auto _ : state) {
benchmark::DoNotOptimize(state.iterations());
}
}
BENCHMARK(BM_empty);
The command:
x86_64-w64-mingw32-g++ test.cpp -std=c++20 -isystem ./include -L./lib -lbenchmark
The errors:
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text+0x106): undefined reference to `__imp__ZN9benchmark5State16StartKeepRunningEv'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x44): undefined reference to `__imp__ZN9benchmark16PrintDefaultHelpEv'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x52): undefined reference to `__imp__ZN9benchmark10InitializeEPiPPcPFvvE'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x5f): undefined reference to `__imp__ZN9benchmark27ReportUnrecognizedArgumentsEiPPc'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x70): undefined reference to `__imp__ZN9benchmark22RunSpecifiedBenchmarksEv'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x76): undefined reference to `__imp__ZN9benchmark8ShutdownEv'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0x9a): undefined reference to `__imp__ZN9benchmark8internal17InitializeStreamsEv'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0xab): undefined reference to `__imp__ZN9benchmark8internal9BenchmarkC2EPKc'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0xc1): undefined reference to `__imp__ZTVN9benchmark8internal17FunctionBenchmarkE'
/home/luo/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/13.0.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cciXACO6.o:test.cpp:(.text.startup+0xcb): undefined reference to `__imp__ZN9benchmark8internal25RegisterBenchmarkInternalEPNS0_9BenchmarkE'
It seemed that the linker couldn't find functions with "imp".
The amazing thing is that when I added "-DBENCHMARK_ENABLE_LTO=ON" and compiled the test with lto, it worked correctly again.
The successful command:
x86_64-w64-mingw32-g++ test.cpp -std=c++20 -isystem ./include -L./lib -lbenchmark -flto
System
- Host: Linux 5.19.0-38-generic
- Target: Windows x86_64-w64-mingw32
- Compiler and version: x86_64-w64-mingw32-g++ 13.0.0 20220812 (experimental) (GCC)
To reproduce
Steps to reproduce the behavior:
- download the release v1.7.1
- ccmake -B build --toolchain toolchain.cmake --install-prefix=/home/luo/benchmark/install -DBUILD_SHARED_LIBS=OFF
toolchain.cmake:
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
- cd build && make install -j
- See error
Expected behavior
The benchmark for static links should also work.
- Lenguaje dominante
- C++
- Estrellas
- 10.5k
- Forks
- 1.8k
- Merge medio
- 2 d 1 h
- PR fusionados (30 d)
- 28
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de google/benchmark
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[BUG] Memory manager counts allocations not part of benchmarkQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
google/benchmark#2149 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
[FR] New "benchstat" output formatPosiblemente ocupada @DenysZm la tomó hace 5 días. Abierto
google/benchmark#2397 · 4 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
google/benchmark#2391 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[FR] Add native Zig bindings via top-level `bindings/zig`Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 42/100
google/benchmark#2266 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de google/benchmark
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
FreqScanner: Run with no enabled frequencies silently stalls in START_SCAN and keeps stale power resultsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
component: tabs platform: macOS
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
zen-browser/desktop#16860 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
metasequoiaime/msime#12003 ·
Los mantenedores suelen responder en 1 día