question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cc_proto_library rules fail to link on Windows with bazel 0.7.0

See original GitHub issue

Description of the problem / feature request / question:

With bazel 0.6.1 cc_proto_library rules build, but with 0.7.0 the rules fail to link. This happens regardless of whether the MSVC wrapper is used. I don’t see any .so outputs from the 0.6.1 build, but 0.7.0 fails when linking .so files.

If possible, provide a minimal example to reproduce the problem:

In an empty directory on Windows:

WORKSPACE

local_repository(
    name = "com_google_protobuf",
    path = "protobuf",
)
local_repository(
    name = "com_google_protobuf_cc",
    path = "protobuf",
)
bind(
    name = "protobuf",
    actual = "@com_google_protobuf//:protobuf",
)
bind(
    name = "protoc",
    actual = "@com_google_protobuf//:protoc",
)

BUILD

cc_proto_library(
    name = "my_cc_proto",
    deps = [":my_proto"],
)

proto_library(
    name = "my_proto",
    srcs = ["my.proto"],
)

my.proto

syntax = "proto2";

message msg {
  optional int32 val = 1;
}

git clone https://github.com/google/protobuf bazel build :my_cc_proto

Environment info

  • Operating System: Windows 10

  • Bazel version (output of bazel info release): 0.7.0

Have you found anything relevant by searching the web?

I posted in bazel-discuss, @laszlocsomor asked for repro

Anything else, information or logs or outputs that would be helpful?

Some of the errors:

error LNK2001: unresolved external symbol "public: __cdecl google::protobuf::internal::LogMessage::LogMessage(enum google::protobuf::LogLevel,char const *,int)" (??0LogMessage@internal@protobuf@google@@QEAA@W4LogLevel@23@PEBDH@Z)
control.pb.o : error LNK2001: unresolved external symbol "public: __cdecl google::protobuf::internal::LogMessage::~LogMessage(void)" (??1LogMessage@internal@protobuf@google@@QEAA@XZ)
control.pb.o : error LNK2001: unresolved external symbol "public: class google::protobuf::internal::LogMessage & __cdecl google::protobuf::internal::LogMessage::operator<<(char const *)" (??6LogMessage@internal@protobuf@google@@QEAAAEAV0123@PEBD@Z)

0.7.0:

cd C:/users/sgreens/appdata/local/temp/_bazel_sgreens/ih0nwrox/execroot/proj
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\8.1\include\\shared;C:\Program Files (x86)\Windows Kits\8.1\include\\um;C:\Program Files (x86)\Windows Kits\8.1\include\\winrt;
    SET LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools;C:\Program Files (x86)\Windows Kits\8.1\bin\x64;C:\Program Files (x86)\Windows Kits\8.1\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\sgreens\AppData\Local\Temp
    SET TMP=C:\Users\sgreens\AppData\Local\Temp
    SET USE_LINKER=1
  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/link.exe /nologo /DLL /IMPLIB:ignored /SUBSYSTEM:CONSOLE /MACHINE:X64 /OPT:REF /OPT:ICF /LTCG @bazel-out/msvc_x64-fastbuild/bin/libmyrule_proto.so-2.params /DEFAULTLIB:msvcrt.lib /DEBUG:FASTLINK /INCREMENTAL:NO.

After setting USE_MSVC_WRAPPER=1:

msvc_link.bat failed: error executing command
  cd C:/users/sgreens/appdata/local/temp/_bazel_sgreens/ih0nwrox/execroot/proj
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\8.1\include\\shared;C:\Program Files (x86)\Windows Kits\8.1\include\\um;C:\Program Files (x86)\Windows Kits\8.1\include\\winrt;
    SET LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Performance Tools;C:\Program Files (x86)\Windows Kits\8.1\bin\x64;C:\Program Files (x86)\Windows Kits\8.1\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\sgreens\AppData\Local\Temp
    SET TMP=C:\Users\sgreens\AppData\Local\Temp
    SET USE_LINKER=1
  external/local_config_cc/wrapper/bin/msvc_link.bat /nologo /DLL /IMPLIB:ignored /SUBSYSTEM:CONSOLE /MACHINE:X64 -Xcompilation-mode=fastbuild /OPT:REF /OPT:ICF /LTCG @bazel-out/msvc_x64-fastbuild/bin/dev/libmyrule_proto.so-2.params /DEFAULTLIB:msvcrt.lib /DEBUG:FASTLINK /INCREMENTAL:NO.  

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
meteorcloudycommented, Nov 20, 2017

I am looking into it

0reactions
meteorcloudycommented, Nov 20, 2017

After 394211b, we support building dynamic library from cc_library. But they are not built by default due to the linking problems.

However, in https://github.com/bazelbuild/bazel/blob/ddb25552f58cb5e822eafd145b5555f163a999e0/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java#L251 when building cc_proto_library, we always add all linking outputs to filesToBuild, which caused this problem.

Sent https://bazel-review.googlesource.com/#/c/bazel/+/21790/ to fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`cc_test` on Bazel@HEAD breaks with ... - GitHub
Description of the bug: On d5c788f, cc_test deps suddenly fail to link on Windows with --experimental_enable_bzlmod. On 092884b, this did ...
Read more >
Using Bazel on Windows
Requirement: To build with Clang, you have to install both LLVM and Visual C++ Build tools, because although you use clang-cl.exe as compiler, ......
Read more >
Expected action_config for 'objc-compile' to be configured
This error signals that your build is not using the correct CROSSTOOL (although I'll admit that I would've expected the CROSSTOOL to be...
Read more >
cmake - bazelbuild/rules_foreign_cc - aspect build
The example for Windows is below, in the section 'Usage on Windows'. ... In BUILD.bazel , we instantiate a cmake rule which behaves...
Read more >
Error building TensorFlow 2.8 in Windows 10
Windows 10, version 20H2 Build 19042.1526. Cuda Toolkit 11.2 cuDNN 8.1. Bazel 4.2.1. Python 3.9.10. MSYS2 64bit
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found