Skip to content

mk: Compile C code on MSVC with /MD #25995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2015
Merged

Conversation

alexcrichton
Copy link
Member

On MSVC there are two ways that the CRT can be linked, either statically or
dynamically. Each object file produced by the compiler is compiled against
msvcrt (a dll) or libcmt (a static library). When the linker is dealing with
more than one object file, it requires that all object files link to the same
CRT, or else the linker will spit out some errors.

For now, compile code with -MD as it seems to appear more often in C libraries
so we'll stick with the same trend.

On MSVC there are two ways that the CRT can be linked, either statically or
dynamically. Each object file produced by the compiler is compiled against
msvcrt (a dll) or libcmt (a static library). When the linker is dealing with
more than one object file, it requires that all object files link to the same
CRT, or else the linker will spit out some errors.

For now, compile code with `-MD` as it seems to appear more often in C libraries
so we'll stick with the same trend.
@alexcrichton
Copy link
Member Author

r? @brson

cc @retep998, @vadimcn

@rust-highfive rust-highfive assigned brson and unassigned nrc Jun 3, 2015
@rust-highfive
Copy link
Contributor

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@retep998
Copy link
Member

retep998 commented Jun 3, 2015

/LTCG isn't required. If a module is compiled for support with LTCG then as soon as the linker comes across it it will switch to LTCG mode automatically. Not passing /LTCG merely causes the linker to waste a bit of time before it realizes it needs to be using LTCG mode, which only matters if any libraries are compiled in LTCG mode. By default most things do not use LTCG, in which case /LTCG will probably just slow things down a bit as the linker spends extra effort being prepared for LTCG data which isn't actually there.

That said, if someone can get some actual numbers on performance differences with /LTCG enabled and disabled, that would help.

@alexcrichton alexcrichton changed the title MSVC: Pass /MD and /LTCG @alexcrichton mk: Compile C code on MSVC with /MD Jun 3, 2015
@alexcrichton alexcrichton changed the title @alexcrichton mk: Compile C code on MSVC with /MD mk: Compile C code on MSVC with /MD Jun 3, 2015
@alexcrichton
Copy link
Member Author

Aha! @retep998 is correct, and I have more investigation to do locally. I have removed that commit now.

@brson
Copy link
Contributor

brson commented Jun 9, 2015

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 9, 2015

📌 Commit cb7d914 has been approved by brson

@bors
Copy link
Collaborator

bors commented Jun 9, 2015

⌛ Testing commit cb7d914 with merge 8a3f5af...

bors added a commit that referenced this pull request Jun 9, 2015
On MSVC there are two ways that the CRT can be linked, either statically or
dynamically. Each object file produced by the compiler is compiled against
msvcrt (a dll) or libcmt (a static library). When the linker is dealing with
more than one object file, it requires that all object files link to the same
CRT, or else the linker will spit out some errors.

For now, compile code with `-MD` as it seems to appear more often in C libraries
so we'll stick with the same trend.
@bors bors merged commit cb7d914 into rust-lang:master Jun 9, 2015
@alexcrichton alexcrichton deleted the msvc-md branch July 10, 2015 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants