Homec4science

Enable building as a shared library (dll) on Windows with Bazel

Authored by Pavel Samolysov <samolisov@gmail.com> on Jan 14 2019, 13:42.

Description

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(

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 <samolisov@gmail.com>

Details

Committed
Pavel Samolysov <samolisov@gmail.com>Jan 14 2019, 14:20
Pushed
trottetDec 4 2019, 13:52
Parents
R9484:0599a7b8410d: Googletest export
Branches
Unknown
Tags
Unknown

Event Timeline

Pavel Samolysov <samolisov@gmail.com> committed R9484:c868da198834: Enable building as a shared library (dll) on Windows with Bazel (authored by Pavel Samolysov <samolisov@gmail.com>).Jan 14 2019, 14:20