@@ -436,7 +436,7 @@ function m.getFileCxxFlags(cfg, filecfg, toolset)
436436 local allExternalIncludedirs = table .join (cfg .externalincludedirs or {}, filecfg .externalincludedirs or {})
437437 local allFrameworkdirs = table .join (cfg .frameworkdirs or {}, filecfg .frameworkdirs or {})
438438 local allIncludedirsafter = table .join (cfg .includedirsafter or {}, filecfg .includedirsafter or {})
439- local includedirs = toolset .getincludedirs (cfg , allIncludedirs , allExternalIncludedirs , allFrameworkdirs , allIncludedirsafter )
439+ local includedirs = toolset .getincludedirs (cfg , allIncludedirs , allExternalIncludedDirs , allFrameworkdirs , allIncludedirsafter )
440440 flags = table .join (flags , includedirs )
441441
442442 local forceincludes = toolset .getforceincludes (filecfg )
@@ -539,6 +539,13 @@ function m.getLdFlags(cfg, toolset)
539539 flags = table .join (flags , rpaths )
540540 end
541541
542+ -- For MSVC shared libraries, add /IMPLIB: to specify the import library location
543+ -- MSVC is Windows-only, so no need to check cfg.system
544+ if cfg .kind == p .SHAREDLIB and toolset == p .tools .msc and not cfg .flags .NoImportLib then
545+ local impLibPath = path .getrelative (cfg .workspace .location , cfg .linktarget .directory ) .. " /" .. cfg .linktarget .name
546+ table.insert (flags , " /IMPLIB:" .. impLibPath )
547+ end
548+
542549 return flags
543550end
544551
@@ -1112,7 +1119,16 @@ function m.linkTarget(cfg)
11121119
11131120 local hasPostBuild = # cfg .postbuildcommands > 0 or cfg .postbuildmessage
11141121
1115- _p (" build %s: %s %s%s" , targetPath , rule , table.concat (cfg ._objectFiles , " " ), implicitDeps )
1122+ -- For MSVC shared libraries with import libraries, list the import library as an implicit output
1123+ -- Dependencies will reference the .lib file (linktarget), which Ninja will know how to build.
1124+ -- MSVC is Windows-only, so no need to check cfg.system
1125+ local implicitOutputs = " "
1126+ if cfg .kind == p .SHAREDLIB and toolset == p .tools .msc and not cfg .flags .NoImportLib then
1127+ local impLibPath = path .getrelative (cfg .workspace .location , cfg .linktarget .directory ) .. " /" .. cfg .linktarget .name
1128+ implicitOutputs = " | " .. impLibPath
1129+ end
1130+
1131+ _p (" build %s%s: %s %s%s" , targetPath , implicitOutputs , rule , table.concat (cfg ._objectFiles , " " ), implicitDeps )
11161132
11171133 if cfg .kind ~= p .STATICLIB then
11181134 _p (" ldflags = $ldflags_%s" , ninja .key (cfg ))
0 commit comments