Skip to content

Commit 4c1dfe4

Browse files
committed
fix(ci): unblock Windows xmake test link (LNK1561)
xmake's gtest package defaults to `gmock = true`, so with `main = true` it links `gmock_main.lib` (not `gtest_main.lib`). On Windows, MSVC's linker doesn't scan inside static libs for the entry point, so it reports `LNK1561: entry point must be defined`. - Disable gmock — we don't use it; this switches the linked main archive to `gtest_main.lib`. - Add `/WHOLEARCHIVE:gtest_main.lib` on Windows to force the entry point object into the link, side-stepping MSVC's lazy lib resolution.
1 parent 938f934 commit 4c1dfe4

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

tests/xmake.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
add_rules("mode.debug", "mode.release")
22
set_languages("c++23")
33

4-
add_requires("gtest", { configs = { main = true } })
4+
add_requires("gtest", { configs = { main = true, gmock = false } })
55

66
target("cmdline_test")
77
set_kind("binary")
88
add_files("cmdline_test.cpp")
99
add_deps("cmdline")
1010
add_packages("gtest")
1111
set_policy("build.c++.modules", true)
12+
-- MSVC 不会从静态库扫描入口点,需要 /WHOLEARCHIVE 把 gtest_main.lib
13+
-- 强制整体链入,否则报 LNK1561: entry point must be defined。
14+
if is_plat("windows") then
15+
add_ldflags("/wholearchive:gtest_main.lib", { force = true })
16+
end

0 commit comments

Comments
 (0)