From 791292f2ee65a4ca8566c3e7a38cbcbf965ddd08 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 7 Feb 2026 00:52:20 +0800 Subject: improve run policy and missing dll --- xmake/core/base/process.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'xmake/core/base/process.lua') diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index 5436115ed..bea469346 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -271,5 +271,48 @@ function process.openv(program, argv, opt) end end +-- get missing dlls +function process._get_missing_dlls(program) + + -- get paths + local pathenv = os.getenv("PATH") or "" + local paths = path.splitenv(pathenv) + table.insert(paths, 1, path.directory(program)) + + -- find missing dlls + local missing = {} + local binutils = require("base/binutils") + local imports = binutils.deplibs(program) or {} + for _, dll in ipairs(imports) do + local found = false + for _, p in ipairs(paths) do + if os.isfile(path.join(p, dll)) then + found = true + break + end + end + if not found then + table.insert(missing, dll) + end + end + return missing +end + +-- get process exit errors +function process.get_exit_errors(program, exitcode) + if is_host("windows") then + -- DLL is missing, 0xC0000135 + if exitcode == -1073741515 and os.isexec(program) then + local missing_dlls = process._get_missing_dlls(program) + if #missing_dlls > 0 then + errors = string.format("system error 0xC0000135 (STATUS_DLL_NOT_FOUND).\nThe application failed to start because the following DLLs were not found:\n - %s\nPlease check your PATH environment variable or copy the missing DLLs to the executable directory.", table.concat(missing_dlls, "\n - ")) + else + errors = string.format("system error 0xC0000135 (STATUS_DLL_NOT_FOUND).\nThe application failed to start because a dependent DLL was not found.\nPlease check your PATH environment variable or copy the missing DLL to the executable directory.") + end + end + end +end + + -- return module: process return process -- cgit v1.3.1