Link errors in cross compilation
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- cmake, cpp
- Ambito
- build-system
Direzione di ricerca
Riproduci il problema utilizzando il toolchain.cmake fornito, la release v1.7.1 e i comandi di compilazione statica. Confronta la configurazione di linking statico generata e il comportamento del linker con il comando -flto funzionante; l’attività è completata quando il test di esempio viene collegato correttamente senza LTO per la destinazione x86_64-w64-mingw32.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 10.5k
- Fork
- 1.8k
- Merge medio
- 2g 1h
- PR unite (30g)
- 28
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/benchmark
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Memory manager counts allocations not part of benchmarkForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
google/benchmark#2149 · 7 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[FR] New "benchstat" output formatForse già presa @DenysZm l’ha presa 5 giorni fa. Aperta
google/benchmark#2397 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
google/benchmark#2391 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[FR] Add native Zig bindings via top-level `bindings/zig`Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
google/benchmark#2266 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google/benchmark
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
component: tabs platform: macOS
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
zen-browser/desktop#16860 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
metasequoiaime/msime#12003 ·
I maintainer di solito rispondono entro 1 giorno