From c868da198834e61cce051775b7e0f9bafd594d89 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Mon, 14 Jan 2019 15:42:36 +0300 Subject: Enable building as a shared library (dll) on Windows with Bazel While the google test library is being built as a shared library using Bazel, so that there is a rule like cc_test( name = "iterator_traits_test", linkstatic = 0, deps = ["@gtest//:gtest_main"], ... ) in a BUILD file, the following error appears on Windows: INFO: Found 1 test target... ERROR: C:/../external/gtest/BUILD.bazel:55:1: output 'external/gtest/gtest.if.lib' was not created ERROR: C:/../external/gtest/BUILD.bazel:55:1: not all outputs were created or valid Target //test:iterator_traits_test failed to build The reason is a missing "win_def_file" attribute of the "gtest" and "gtest_main" rules in the BUILD.bazel inside the google test library package. The "windows_export_all_symbols" feature is added to the rules, this feature forces Bazel to export all symbols from the google test library to linker. I believe exporting all symbols from a testing library makes no problem for the application from a point of view on encapsulation. Signed-off-by: Pavel Samolysov --- BUILD.bazel | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'BUILD.bazel') diff --git a/BUILD.bazel b/BUILD.bazel index 4dbaa271..a000471d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -104,12 +104,20 @@ cc_library( ], "//conditions:default": [], }), + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }) ) cc_library( name = "gtest_main", srcs = ["googlemock/src/gmock_main.cc"], deps = [":gtest"], + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }) ) # The following rules build samples of how to use gTest. -- cgit v1.2.3