Skip to content

Commit

Permalink
MSVC: attempt to choose msvcrt.lib vs libcmt.lib correctly
Browse files Browse the repository at this point in the history
See Issue #2120: if we specify /MD for copts, we should attempt to use
MSVCRTx.lib instead of LIBCMTx.lib.

Closes #2862.

PiperOrigin-RevId: 154032031
  • Loading branch information
steven-johnson authored and vladmos committed Apr 24, 2017
1 parent 92b14b0 commit 0512a0e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/cpp/wrapper/bin/pydir/msvc_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ def Run(self, argv):
raise ValueError('Must specify compilation mode '
'(-Xcompilation-mode={dbg,fastbuild,opt})')

if parser.compilation_mode == 'dbg':
default_args.insert(0, 'libcmtd.lib')
else:
default_args.insert(0, 'libcmt.lib')
rtlib = 'libcmt%s.lib'
# attempt to choose the right runtime library if we can
for opt in reversed(parser.options):
if opt in ['/MT', '/MTd']:
rtlib = 'msvcrt%s.lib'
break
default_args.insert(0, rtlib %
('d' if parser.compilation_mode == 'dbg' else ''))

return self.RunBinary(tool, default_args + parser.options,
parser.target_arch, parser)
Expand Down

0 comments on commit 0512a0e

Please sign in to comment.