From ae2b601bea6730629893327c40f5581ee8d3a3dd Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Tue, 4 Nov 2025 19:41:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Don=E2=80=99t=20link=20targets=20with=20mai?= =?UTF-8?q?n=20function=20against=20//:gtest=5Fmain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This works only because the linker discards the main function from the //:gtest_main library, otherwise the symbol would be duplicated. --- googletest/test/BUILD.bazel | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 9575ae11a4..7561d3c165 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -125,7 +125,7 @@ cc_test( name = "googletest-listener-test", size = "small", srcs = ["googletest-listener-test.cc"], - deps = ["//:gtest_main"], + deps = ["//:gtest"], ) cc_test( @@ -358,7 +358,7 @@ cc_test( name = "gtest_skip_in_environment_setup_test", size = "small", srcs = ["gtest_skip_in_environment_setup_test.cc"], - deps = ["//:gtest_main"], + deps = ["//:gtest"], ) py_test( @@ -417,7 +417,7 @@ cc_binary( name = "googletest-catch-exceptions-no-ex-test_", testonly = 1, srcs = ["googletest-catch-exceptions-test_.cc"], - deps = ["//:gtest_main"], + deps = ["//:gtest"], ) cc_binary( @@ -425,7 +425,7 @@ cc_binary( testonly = 1, srcs = ["googletest-catch-exceptions-test_.cc"], copts = ["-fexceptions"], - deps = ["//:gtest_main"], + deps = ["//:gtest"], ) py_test( From d54d30fecb5d37d8d50e8123f715bea206e72ca3 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Tue, 4 Nov 2025 19:33:13 +0100 Subject: [PATCH 2/2] Add alwayslink = True to //:gtest_main Fixes #4868 --- BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.bazel b/BUILD.bazel index 5ab4e114f6..03392c6b48 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -187,6 +187,7 @@ cc_library( "//conditions:default": [], }), deps = [":gtest"], + alwayslink = True, ) # The following rules build samples of how to use gTest.