Any way to perform implicit linking on Windows?

214 views
Skip to first unread message

Ben Vanik

unread,
Jun 30, 2017, 11:33:33 PM6/30/17
to bazel-discuss
Hello!
I can't seem to figure out how to perform implicit linking between a cc_binary dll and cc_binary exe. Is this supported and I'm just not doing it right, or something I should file a feature request for?


As opposed to explicit linking, which is demonstrated in the bazel sample here (https://github.com/bazelbuild/bazel/tree/master/examples/windows/dll), implicit linking needs to pass the .lib generated during linking of the dll into its dependencies. Though the .lib is generated when bazel builds the dll I can't seem to find a way to get bazel to expose it or accept it in dependent rules.

In the dll example I'd expect to be able to have a hello-world-implicit.cpp that did the following:
```
#include <stdio.h>
#include <windows.h>
__declspec(dllimport) char *get_time();
__declspec(dllimport) void say_hello(char *message);

int main() {
  char *now = get_time();
  say_hello(now);
  return 0;
}
```

And a build rule like:
```
cc_binary(
    name = "hello-implicit",
    srcs = [
        "hello-world-implicit.cpp",
    ],
    deps = [":hellolib.dll"],
)
```

Building :hellolib will cause a hellolib.lib to be written to blaze-bin but I can't get at it and bazel itself is not passing it to the linking of the exe so get_time and say_hello will be unresolved.

Thoughts? Workarounds?

Ben Vanik

unread,
Jun 30, 2017, 11:47:53 PM6/30/17
to bazel-discuss
I was able to get a successful build of my project by manually copying the .lib files to the bizarre path under blaze-bin the dlls are placed in. In my case libEGL.dll was here:
```
(workspace)\bazel-bin\_solib_x64_windows\_U@com_Ugithub_Ugoogle_Uswiftshader_S_S_Cswiftshader___Uexternal_Scom_Ugithub_Ugoogle_Uswiftshader\
```
And by placing the libEGL.lib in there as well as adding the following to my linkopts it built: "-Wl,libEGL.lib"

Unfortunately this is working outside of bazel and the next time the dll is rebuilt that directory is blasted away :(
Is there a way to get the lib file to be copied as an output along with the dll?

Dmitry Lomov

unread,
Jul 1, 2017, 3:11:13 AM7/1/17
to Ben Vanik, bazel-discuss
This is not supported yet - please file a feature request to track.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/669a0d70-4657-4362-858f-ca842aa2490e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Google Germany GmbH
Erika-Mann-Straße 33, 80636 München, Germany

Ben Vanik

unread,
Jul 1, 2017, 3:33:57 AM7/1/17
to bazel-discuss, benv...@google.com
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages