Skip to content

Commit 612a84c

Browse files
committed
fix: Windows linker flags — no -L/-rpath/-static (MSVC linker)
Clang targeting x86_64-pc-windows-msvc uses MSVC's link.exe which doesn't understand -L, -Wl,-rpath, or -static. Clear ldflags on Windows — MSVC runtime is linked automatically.
1 parent 577bbcf commit 612a84c

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/build/flags.cppm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,32 @@ CompileFlags compute_flags(const BuildPlan& plan) {
149149
// Link flags
150150
f.staticStdlib = plan.manifest.buildConfig.staticStdlib;
151151
f.linkage = plan.manifest.buildConfig.linkage;
152-
#if defined(__APPLE__)
152+
#if defined(_WIN32)
153+
// Windows: MSVC linker handles static/dynamic linking differently
154+
std::string full_static;
155+
std::string static_stdlib;
156+
#elif defined(__APPLE__)
153157
// macOS does not support full static linking (libSystem must be dynamic)
154158
std::string full_static;
159+
std::string static_stdlib = (f.staticStdlib && !isClang) ? " -static-libstdc++" : "";
155160
#else
156161
std::string full_static = (f.linkage == "static") ? " -static" : "";
157-
#endif
158162
std::string static_stdlib = (f.staticStdlib && !isClang) ? " -static-libstdc++" : "";
163+
#endif
159164
std::string runtime_dirs;
165+
#if !defined(_WIN32)
166+
// -L and -rpath are ELF/Mach-O linker flags; MSVC linker doesn't use them.
160167
for (auto& dir : plan.toolchain.linkRuntimeDirs) {
161168
runtime_dirs += " -L" + escape_path(dir);
162169
runtime_dirs += " -Wl,-rpath," + escape_path(dir);
163170
}
171+
#endif
164172

165-
#if defined(__APPLE__)
173+
#if defined(_WIN32)
174+
// Windows: Clang targeting MSVC links against MSVC runtime automatically.
175+
// No -L/-rpath/-static flags needed.
176+
f.ld = "";
177+
#elif defined(__APPLE__)
166178
// macOS linking strategy:
167179
// - No --sysroot: SDK .tbd stubs miss libc++abi exports.
168180
// - No -L<llvm>/lib: xlings LLVM's libc++.dylib doesn't pull in

0 commit comments

Comments
 (0)