Open 24bit-xjkp opened 1 year ago
I suspect the cause is symbol visibility. https://github.com/google/benchmark/blob/1b507cbf104f7226ade1dd23abe92630e818d54b/CMakeLists.txt#L44-L46 Perhaps this either is not working on windows at all, or does not correctly handle using non-MSVC compilers: https://github.com/google/benchmark/blob/1b507cbf104f7226ade1dd23abe92630e818d54b/include/benchmark/export.h#L4-L14
I tried to build benchmark on windows. Clang with "-DBUILD_SHARED_LIBS=OFF" generated some other errors.
lld-link: error: undefined symbol: __declspec(dllimport) int __cdecl benchmark::internal::InitializeStreams(void)
>>> referenced by C:\Users\ADMINI~1.SKY\AppData\Local\Temp\.xmake\230416\_19FB25C6824C4B00894B9FB808826310.o:(void __cdecl `dynamic initializer for 'benchmark::internal::stream_init_anchor''(void))
lld-link: error: undefined symbol: __declspec(dllimport) private: void __cdecl benchmark::State::StartKeepRunning(void)
>>> referenced by C:\Users\ADMINI~1.SKY\AppData\Local\Temp\.xmake\230416\_19FB25C6824C4B00894B9FB808826310.o:(void __cdecl BM_empty(class benchmark::State &))
lld-link: error: undefined symbol: __declspec(dllimport) private: void __cdecl benchmark::State::FinishKeepRunning(void)
>>> referenced by C:\Users\ADMINI~1.SKY\AppData\Local\Temp\.xmake\230416\_19FB25C6824C4B00894B9FB808826310.o:(void __cdecl BM_empty(class benchmark::State &))
lld-link: error: undefined symbol: __declspec(dllimport) public: __cdecl benchmark::internal::FunctionBenchmark::FunctionBenchmark(char const *, void (__cdecl *)(class benchmark::State &))
>>> referenced by C:\Users\ADMINI~1.SKY\AppData\Local\Temp\.xmake\230416\_19FB25C6824C4B00894B9FB808826310.o:(void __cdecl `dynamic initializer for 'benchmark_uniq_2_benchmark_''(void))
lld-link: error: undefined symbol: __declspec(dllimport) class benchmark::internal::Benchmark * __cdecl benchmark::internal::RegisterBenchmarkInternal(class benchmark::internal::Benchmark *)
>>> referenced by C:\Users\ADMINI~1.SKY\AppData\Local\Temp\.xmake\230416\_19FB25C6824C4B00894B9FB808826310.o:(void __cdecl `dynamic initializer for 'benchmark_uniq_2_benchmark_''(void))
But it works correctly when it is built with "-DBUILD_SHARED_LIBS=ON".
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:
The command:
The errors:
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:
System
To reproduce Steps to reproduce the behavior:
Expected behavior The benchmark for static links should also work.