Skip to content

Commit d97b4af

Browse files
committed
mklldeps: Don't link stdc++/c++ on MSVC
These libraries don't exist! The linker for MSVC is highly likely to not pass `/NODEFAULTLIB` in which case the right standard library will automatically be selected.
1 parent af56e2e commit d97b4af

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/etc/mklldeps.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ def run(args):
8080
assert('stdlib=libc++' not in out)
8181
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
8282
else:
83+
# Note that we use `cfg_attr` here because on MSVC the C++ standard library
84+
# is not c++ or stdc++, but rather the linker takes care of linking the
85+
# right standard library.
8386
if 'stdlib=libc++' in out:
84-
f.write("#[link(name = \"c++\")]\n")
87+
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n")
8588
else:
86-
f.write("#[link(name = \"stdc++\")]\n")
89+
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"stdc++\"))]\n")
8790

8891
# Attach everything to an extern block
8992
f.write("extern {}\n")

0 commit comments

Comments
 (0)