You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
On Windows: Linking against standard libraries #1945
For C++, linkopts allows one to specify linker options. However, it also states that:
Each element of this list that does not start with $ or - is assumed to be the label of a target in deps. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in deps.
As far as I can see, this means that I cannot specify plain arguments to the linker, e.g. User32.lib, as required for some system libraries.
I got it to link to the system library by copying it locally, specifying it as a srcs in a cc_library, and referring to the library's label in both deps and linkopts. However, copying a system library seems like a bad idea. The C++ system header files are already picked up automatically by Bazel, so maybe these libraries should be, too. I noticed that CMake automatically links against some libraries on Windows, i.e. it links against user32.lib advapi32.lib gdi32.lib when compiling openssl on Windows without explicitly specifying these anywhere.
From Bazel 0.5.3, we no longer use wrapper script to invoke MSVC compiler anymore. So -Wl,<lib> won't be translated, please use -DEFAULTLIB:<lib> instead.
Activity
hermione521 commentedon Oct 14, 2016
@meteorcloudy
laszlocsomor commentedon Oct 24, 2016
You can use
linkopts = ["-Wl,user32.lib", "-Wl,advapi32.lib"].See the command line translation here:
bazel/tools/cpp/wrapper/bin/pydir/msvc_link.py
Line 40 in 088bbc6
From Bazel 0.5.3, we no longer use wrapper script to invoke MSVC compiler anymore. So
-Wl,<lib>won't be translated, please use-DEFAULTLIB:<lib>instead.Helcaraxan commentedon Oct 24, 2016
Thanks for the solution!
grandseiken commentedon Oct 24, 2016
Thanks laszlo! You walked out that elevator like a boss!
laszlocsomor commentedon Oct 24, 2016
@grandseiken : hey Stuart, small world :)