Remove gtest_main from Bazel test_util and benchmark deps In googletest 1.18.0, @googletest//:gtest_main sets alwayslink = True, so linking it transitively through //:test_util pulls gmock_main.o into every Bazel benchmark binary and collides with BENCHMARK_MAIN() / main(). Depend on @googletest//:gtest in //:test_util, move @googletest//:gtest_main (alongside @googletest//:gtest) to TEST_DEPS, and give benchmark binaries their own BENCHMARK_DEPS without gtest_main. Change-Id: I37d549cb8dcffe58d7a194de2246acde3bb2b88f
diff --git a/BUILD b/BUILD index b3c5373..9a74268 100644 --- a/BUILD +++ b/BUILD
@@ -60,7 +60,7 @@ ], deps = [ "//:ceres", - "@googletest//:gtest_main", + "@googletest//:gtest", ], ) @@ -175,6 +175,8 @@ "//:ceres", "//:test_util", "@eigen//:eigen", + "@googletest//:gtest", + "@googletest//:gtest_main", ] # Instantiate all the tests with a template. @@ -211,11 +213,18 @@ "//conditions:default": [], }) +BENCHMARK_DEPS = [ + "//:ceres", + "//:test_util", + "@eigen//:eigen", + "@google_benchmark//:benchmark", +] + [cc_binary( name = benchmark_name, srcs = ["internal/ceres/" + benchmark_name + ".cc"], copts = BENCHMARK_COPTS, - deps = TEST_DEPS + ["@google_benchmark//:benchmark"], + deps = BENCHMARK_DEPS, ) for benchmark_name in [ "autodiff_manifold_benchmark", "block_jacobi_preconditioner_benchmark", @@ -239,5 +248,5 @@ "internal/ceres/cost_function_differentiation_benchmark.cc", ], copts = BENCHMARK_COPTS, - deps = TEST_DEPS + ["@google_benchmark//:benchmark"], + deps = BENCHMARK_DEPS, )