Repository navigation
Link against the runtime import library on Windows - #328
Merged
Merged
Conversation
mojo build failed at the link step with "bad file type. Did you specify a DLL instead of an import library?". mojo-build.cpp puts getCompilerRTPath() on the linker command line, which is lib/ plus whatever the target calls a shared library, so targeting Windows it is the DLL. A COFF linker cannot read one. The list of names a Windows shared library defines is in the import library beside it, and that is the file a link needs. getCompilerRTImportLibraryPath already exists and ObjectCompiler already uses it. This was the one place left that named the DLL. The error when the file is missing now says which file it looked for, because "unable to locate Mojo CompilerRT library" with no path was not much to go on when the answer is that it was looking for the wrong one.
tamnd
force-pushed
the
compilerrt-import-lib
branch
from
September 9, 2026 07:44
7ee929e to
17ad998
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #327.
mojo buildon Windows stopped at the link step:mojo-build.cppputconfig.getCompilerRTPath()on the linker command line. That islib/plus whatever the target platform calls a shared library, so targeting Windows it is the DLL, and a COFF linker cannot read one. The list of names a Windows shared library defines lives in the import library beside it, and the DLL is what the loader picks up afterwards by the name recorded in the import.getCompilerRTImportLibraryPathalready existed andObjectCompileralready used it. This was the one place left that named the DLL.The error for a missing file now says which file, since "unable to locate Mojo CompilerRT library" with no path was not much help when the problem was that it was looking for the wrong one.
Verified by cross building a Windows
mojo.exe, staging it with anlld-link.exenext to it and the runtime underlib/, and building a hello world on a Windows host:That is the first Mojo program compiled to an executable on Windows by a Windows compiler. Before this change the same command got as far as the linker and no further.
The built binary imports
KERNEL32.dllandKGENCompilerRTShared.dlland nothing else, and the runtime DLL has to be beside it to start, which is the packaging question in #319 rather than anything here.