Issues Linking Google Benchmark with g++ on Windows (MSYS2) using vcpkg

I’m trying to use Google Benchmark with the g++ compiler on Windows. I installed the library using the vcpkg package manager with the triplet x64-mingw-static.

Here is the command I used to install it:

vcpkg install benchmark:x64-mingw-static

To compile my benchmark code, I am using the following g++ command:

g++ -std=c++23 test_benchmark.cpp -isystem "C:\Program Files\vcpkg\installed\x64-mingw-static\include" "C:\Program Files\vcpkg\installed\x64-mingw-static\lib\benchmark.a" "C:\Program Files\vcpkg\installed\x64-mingw-static\lib\benchmark_main.a" -lpthread -o benchmark_test.exe

However, I am getting the following errors:

C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find C:Program Filesvcpkginstalledx64-mingw-staticlibbenchmark.a: No such file or directory
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find C:Program Filesvcpkginstalledx64-mingw-staticlibbenchmark_main.a: No such file or directory
collect2.exe: error: ld returned 1 exit status

I have verified that the files benchmark.a and benchmark_main.a exist in the specified directory. I also tried using the -L flag to specify the library directory and the -l flag to link against the libraries, but encountered similar issues. Here is the command:

g++ -std=c++23 test_benchmark.cpp -isystem "C:\Program Files\vcpkg\installed\x64-mingw-static\include" -L "C:\Program Files\vcpkg\installed\x64-mingw-static\lib" -lbenchmark -lbenchmark_main -lpthread -o benchmark_test.exe

This resulted in the following errors:

C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x66): undefined reference to `__imp__ZN9benchmark5State16StartKeepRunningEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0xf4): undefined reference to `__imp__ZN9benchmark5State17FinishKeepRunningEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x1a3): undefined reference to `__imp__ZN9benchmark5State16StartKeepRunningEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x23b): undefined reference to `__imp__ZN9benchmark5State17FinishKeepRunningEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x2ca): undefined reference to `__imp__ZN9benchmark16PrintDefaultHelpEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x2df): undefined reference to `__imp__ZN9benchmark10InitializeEPiPPcPFvvE'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x2f1): undefined reference to `__imp__ZN9benchmark27ReportUnrecognizedArgumentsEiPPc'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x305): undefined reference to `__imp__ZN9benchmark22RunSpecifiedBenchmarksEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x30e): undefined reference to `__imp__ZN9benchmark8ShutdownEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x335): undefined reference to `__imp__ZN9benchmark8internal17InitializeStreamsEv'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x398): undefined reference to `__imp__ZN9benchmark8internal25RegisterBenchmarkInternalEPNS0_9BenchmarkE'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text+0x409): undefined reference to `__imp__ZN9benchmark8internal25RegisterBenchmarkInternalEPNS0_9BenchmarkE'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text$_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE[_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE]+0x22): undefined reference to `__imp__ZN9benchmark8internal9BenchmarkC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
C:/Program Files/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UsersbenjiAppDataLocalTempccrIFsd8.o:test_benchmark:(.text$_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE[_ZN9benchmark8internal17FunctionBenchmarkC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPFvRNS_5StateEE]+0x2b): undefined reference to `__imp__ZTVN9benchmark8internal17FunctionBenchmarkE'
collect2.exe: error: ld returned 1 exit status

My cpp is:

#include <benchmark/benchmark.h>

static void BM_StringCreation(benchmark::State& state) {
    for (auto _ : state)
        std::string empty_string;
}
BENCHMARK(BM_StringCreation);

static void BM_StringCopy(benchmark::State& state) {
    std::string x = "hello";
    for (auto _ : state)
        std::string copy(x);
}
BENCHMARK(BM_StringCopy);

BENCHMARK_MAIN();

I’ve ensured that the vcpkg installation is integrated with my environment and that the include paths are correct. I’m currently using g++ from the MSYS2 distribution.

Can anyone help me figure out why the linker can’t find the libraries and how to properly link Google Benchmark with g++ on Windows?

New contributor

Benjiro Fukuoka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật