xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

command line conversion error #5324

Closed fxliang closed 2 months ago

fxliang commented 2 months ago

Xmake 版本

2.9.3+HEAD.4458811b1

操作系统版本和架构

Microsoft Windows 10 10.0.19044

描述问题

build process as bellow

C:\Users\user_name\Desktop\test>xmake -v
[ 50%]: compiling.release main.cpp
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\cl.exe" -c -nologo "-IC:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\ATLMFC\\include" "-IC:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\include" "-IC:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\include\\um" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\ucrt" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\shared" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\um" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\winrt" "-IC:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\cppwinrt" /EHsc -Fobuild\.objs\test\windows\x64\release\main.cpp.obj main.cpp
[ 75%]: linking.release test.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /MANIFEST "/MANIFESTUAC:\"level='asInvoker' uiAccess='false'\"" /manifest:embed "/manifestinput:\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\Include\\Manifest\\PerMonitorHighDPIAware.manifest\"" -out:build\windows\x64\release\test.exe build\.objs\test\windows\x64\release\main.cpp.obj
error: LINK : fatal error LNK1327: failure during running mt.exe

modified the link command and it worked

C:\Users\user_name\Desktop\test>"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /manifestinput:"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\Include\\Manifest\\PerMonitorHighDPIAware.manifest" -out:build\windows\x64\release\test.exe build\.objs\test\windows\x64\release\main.cpp.obj

key diff is on the ldflags

- /MANIFEST "/MANIFESTUAC:\"level='asInvoker' uiAccess='false'\"" /manifest:embed "/manifestinput:\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\Include\\Manifest\\PerMonitorHighDPIAware.manifest\"" 
+ /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /manifestinput:"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.29.30133\\Include\\Manifest\\PerMonitorHighDPIAware.manifest"

期待的结果

build successfully

工程配置

main.cpp

#include <iostream>
int main(int argc, char* argv[]) {
  std::cout << "hello test" << std::endl;
  return 0;
}

xmake.lua

target("test")
  set_kind("binary")
  local atl_lib_dir = ''
  local dpi_manifest = ''
  for include in string.gmatch(os.getenv("include"), "([^;]+)") do
    if atl_lib_dir=='' and include:match(".*ATLMFC\\include\\?$") then
      atl_lib_dir = include:replace("include$", "lib")
      dpi_manifest = include:replace("ATLMFC\\include$", "Include\\Manifest\\PerMonitorHighDPIAware.manifest")
    end
    add_includedirs(include)
  end
  add_ldflags('/MANIFEST')
  add_ldflags('/MANIFESTUAC:' .. '"level=' .. "'asInvoker' uiAccess=" .. "'false'" .. '"')
  add_ldflags('/manifest:embed' .. ' /manifestinput:"' .. dpi_manifest .. '"')

  add_files("main.cpp")

附加信息和错误日志

none

waruqi commented 2 months ago

set_policy("windows.manifest.uac", "invoker")add_files("src/*.manifest")

https://xmake.io/#/guide/build_policies?id=windowsmanifestuac https://github.com/xmake-io/xmake/issues/1241#issuecomment-782985651 https://github.com/xmake-io/xmake/pull/4369#issuecomment-1797980473 https://github.com/xmake-io/xmake/blob/dev/xmake/rules/platform/windows/manifest/xmake.lua

fxliang commented 2 months ago

也就是,只能复制那个PerMonitorDPIAware.manifest出来放$(projectdir)下来用了?

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


In other words, you can only copy the PerMonitorDPIAware.manifest and put it in $(projectdir) for use?

waruqi commented 2 months ago

rule 里面走 target:add("files", "xxx.manifest") 也可以。。

如果非要自己 add ldflags,和参考上面链接里面的代码实现。。你 add 的方式也不对

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


You can also use target:add("files", "xxx.manifest") in the rule. .

If you have to add ldflags yourself, please refer to the code implementation in the link above. . The way you add is also wrong

fxliang commented 2 months ago

试了这样添加确实是可以的,只不过有一个target 要admin,又想permonitordpiaware,目前这样似乎是不行的。我见有代码注释描述只要有manifest就取消uac

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


It is indeed possible to add it this way, but there is a target that requires admin, and I want to monitordpiaware. This seems to be not possible at the moment. I saw a code comment describing how to cancel uac as long as there is a manifest.

waruqi commented 2 months ago

https://github.com/xmake-io/xmake/blob/dev/xmake/rules/platform/windows/manifest/xmake.lua

当初是为了解决这个 https://github.com/xmake-io/xmake/pull/4362

不行,就自己 add ldflags 好了,你之前的配置语法不对而已。参考这个自己改下就行了

https://github.com/xmake-io/xmake/blob/46952b01a1f8b8e0dc8b68f4b5228ed2f466aa39/xmake/rules/platform/windows/manifest/xmake.lua#L69

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


https://github.com/xmake-io/xmake/blob/dev/xmake/rules/platform/windows/manifest/xmake.lua

It was originally to solve this https://github.com/xmake-io/xmake/pull/4362

No, just add ldflags yourself. Your previous configuration syntax was just wrong. Just refer to this and change it yourself.

https://github.com/xmake-io/xmake/blob/46952b01a1f8b8e0dc8b68f4b5228ed2f466aa39/xmake/rules/platform/windows/manifest/xmake.lua#L69

fxliang commented 2 months ago

OK