Commit c868da19 authored by Pavel Samolysov's avatar Pavel Samolysov
Browse files

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: default avatarPavel Samolysov <samolisov@gmail.com>
parent 0599a7b8
...@@ -104,12 +104,20 @@ cc_library( ...@@ -104,12 +104,20 @@ cc_library(
], ],
"//conditions:default": [], "//conditions:default": [],
}), }),
features = select({
":windows": ["windows_export_all_symbols"],
"//conditions:default": [],
})
) )
cc_library( cc_library(
name = "gtest_main", name = "gtest_main",
srcs = ["googlemock/src/gmock_main.cc"], srcs = ["googlemock/src/gmock_main.cc"],
deps = [":gtest"], deps = [":gtest"],
features = select({
":windows": ["windows_export_all_symbols"],
"//conditions:default": [],
})
) )
# The following rules build samples of how to use gTest. # The following rules build samples of how to use gTest.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment