xmake-io / xmake

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

Windows Applications aren't configured correctly using set_kind("binary") #4785

Closed Lyuu17 closed 7 months ago

Lyuu17 commented 8 months ago

Xmake Version

2.8.7

Operating System Version and Architecture

Windows 11

Describe Bug

set_kind doesn't have any configuration property like CMake does so attempting to run the .exe, it just doesn't work.

Expected Behavior

A fully working Windows application

Project Configuration

target("ServerBrowserApplicationWX")
    set_kind("binary")
    add_files(sources)
    add_deps("LauncherLibrary", "CoreLibrary")
    add_packages("tinyxml2", "fmt", "eventpp", "libcurl", "wxwidgets", "nlohmann_json")
    add_includedirs("include")
    set_pcxxheader("src/pch.hpp")
    add_defines("_UNICODE")

Additional Information and Error Logs

Trying to run it with xmake run gives:

image

Lyuu17 commented 8 months ago

I researched a bit, it would be this /SUBSYSTEM linker flag and "Console" is the current one used by "binary", with "Windows" the one I need.

SirLynix commented 8 months ago

This is not a bug, xmake doesn't set the /subsystem flag, /subsystem:console is just the default value from MSVC.

You can use add_ldflags("/subsystem:windows") in this case

Lyuu17 commented 8 months ago

You can use add_ldflags("/subsystem:windows") in this case

Still builds like a console instead of windows, and vscode seems to not recognize it either

image

star-hengxing commented 8 months ago
add_ldflags("/subsystem:windows", {force = true})
waruqi commented 8 months ago

binary kind will not add any flags. if you want to build windows app. you should use "win.sdk.application" rule, it will set binary kind and windows subsystem.

https://xmake.io/#/guide/project_examples?id=winsdk-application-program

https://github.com/xmake-io/xmake/blob/9b8384ff002380fce4ba8ca4cd3f6e0e354fb9dc/tests/projects/windows/winsdk/windemo/xmake.lua#L4

Lyuu17 commented 8 months ago
add_ldflags("/subsystem:windows", {force = true})

Still compiles as "console"

binary kind will not add any flags. if you want to build windows app. you should use "win.sdk.application" rule, it will set binary kind and windows subsystem.

https://xmake.io/#/guide/project_examples?id=winsdk-application-program

https://github.com/xmake-io/xmake/blob/9b8384ff002380fce4ba8ca4cd3f6e0e354fb9dc/tests/projects/windows/winsdk/windemo/xmake.lua#L4

Thanks, docs are a bit confusing, but still, same as ldflags, compiles as console (I think so, I'm comparing with Visual Studio generating the cmakelists and then .sln)

[ 92%]: linking.release ServerBrowserApplicationWX.exe
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\bin\\HostX86\\x86\\link.exe" -nologo -dynamicbase -nxcompat -machine:x86 -libpath:C:\Users\lucx\AppData\Local\.xmake\packages\l\libcurl\8.5.0\9298462f501e4bdfb979fcd6fbb97d01\lib -libpath:C:\Users\lucx\AppData\Local\.xmake\packages\w\wxwidgets\master\af705bc0e66f4f108a3a47c7ee859189\lib -libpath:build\windows\x86\release -libpath:C:\Users\lucx\AppData\Local\.xmake\packages\t\tinyxml2\10.0.0\f114b247ea1e417493c76700ae5c1c5f\lib -libpath:C:\Users\lucx\AppData\Local\.xmake\packages\f\fmt\10.2.1\0897ead68a554e21b2546cd5fd4492a6\lib /opt:ref /opt:icf libcurl.lib wxbase33u.lib wxbase33u_net.lib wxbase33u_xml.lib wxexpat.lib wxjpeg.lib wxlexilla.lib wxmsw33u_adv.lib wxmsw33u_aui.lib wxmsw33u_core.lib wxmsw33u_gl.lib wxmsw33u_html.lib wxmsw33u_media.lib wxmsw33u_propgrid.lib wxmsw33u_qa.lib wxmsw33u_ribbon.lib wxmsw33u_richtext.lib wxmsw33u_stc.lib wxmsw33u_webview.lib wxmsw33u_xrc.lib wxpng.lib wxregexu.lib wxscintilla.lib wxtiff.lib wxzlib.lib LauncherLibrary.lib CoreLibrary.lib tinyxml2.lib fmt.lib kernel32.lib gdi32.lib winspool.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib comdlg32.lib setupapi.lib shlwapi.lib strsafe.lib crypt32.lib wldap32.lib winmm.lib ws2_32.lib user32.lib advapi32.lib ole32.lib shell32.lib -subsystem:windows /manifestinput:applications\ServerBrowserApplicationWX\ServerBrowserApplicationWX.manifest /manifestuac:no /manifest:embed -out:build\windows\x86\release\ServerBrowserApplicationWX.exe build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\dialogs\AboutDialog.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\dialogs\AddServerDialog.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\dialogs\SettingsDialog.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\Browser.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\main.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\MyApp.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\src\MyFrame.cpp.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\applications\ServerBrowserApplicationWX\ServerBrowserApplicationWX.rc.obj build\.objs\ServerBrowserApplicationWX\windows\x86\release\gens\applications\ServerBrowserApplicationWX\src\cxx\pch.hpp.pch.obj

image

msbuild build.log

SirLynix commented 8 months ago

image No, it does compile with /subsystem:windows.

Why are you generating a cmakelists then a .sln? You can generate a Visual Studio project using either vs or vsxmake project generator.

Lyuu17 commented 8 months ago

No, it does compile with /subsystem:windows.

It compiles, it links, but it doesn't run. Once I changed manually in the project settings generated by xmake (and cmake) to Subsystem: Windows I assumed it was a linking issue

Why are you generating a cmakelists then a .sln? You can generate a Visual Studio project using either vs or vsxmake project generator.

My bad, sorry. Generating through vsxmake setups correctly the Subsystem:

image

Trying to run it:

image

Somehow vsxmake is different than doing xmake > cmake > sln?

waruqi commented 8 months ago

If possible, use xmake to build the project directly.

Lyuu17 commented 8 months ago

If possible, use xmake to build the project directly.

Visual Studio used xmake in the background

waruqi commented 8 months ago

yeah, vsxmake will use it. please use vsxmake or use xmake directly.

Lyuu17 commented 8 months ago

yeah, vsxmake will use it. please use vsxmake or use xmake directly.

Ok, but program doesn't work using xmake anyway, and I don't know why. It used to work in the cmake, and if I generate the cmakefiles it does indeed work if Subsystem is changed manually

waruqi commented 8 months ago

Ok, but program doesn't work using xmake anyway

please show me your xmake.lua and all logs.

xmake f -cvD
xmake -rvD
Lyuu17 commented 8 months ago

xmake.lua image

xmake f -cvD first.log

xmake -rvD second.log

Issues-translate-bot commented 8 months ago

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


xmake.lua image

xmake f -cvD first.log

xmake -rvD second.log

waruqi commented 8 months ago

-subsystem:windows /manifestinput:applications\ServerBrowserApplicationWX\ServerBrowserApplicationWX.manifest /manifestuac:no /manifest:embed -out:build\windows\x86\release\ServerBrowserApplicationWX.exe

-subsystem:windows has been added.

Lyuu17 commented 8 months ago

-subsystem:windows /manifestinput:applications\ServerBrowserApplicationWX\ServerBrowserApplicationWX.manifest /manifestuac:no /manifest:embed -out:build\windows\x86\release\ServerBrowserApplicationWX.exe

-subsystem:windows has been added.

yes, and trying to run it: image

waruqi commented 8 months ago

you can debug it, maybe .dll PATH issues, maybe your code has bug, or ...

Lyuu17 commented 8 months ago

you can debug it, maybe .dll PATH issues, maybe your code has bug, or ...

works fine in cmake, no code changed and linking against the wxwidgets lib generated by xmake

waruqi commented 8 months ago

you can check ldflags difference between cmake and xmake.

waruqi commented 7 months ago

Or you can provide a complete reproducible project and I'll take a look at it.

Lyuu17 commented 7 months ago

Found the issue, adding this flag fixes it. image

SirLynix commented 7 months ago

This flag is enabled by default (see https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally), I doubt it changes anything.

waruqi commented 7 months ago

This flag is enabled by default (see https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally), I doubt it changes anything.

maybe /opt:ref /opt:icf will disable this flag by default? set_strip(true) or release mode will add them.

Most programs can be linked incrementally. However, some changes are too great, and some options are incompatible with incremental linking. LINK performs a full link if any of the following options are specified:

Link Incrementally isn't selected (/INCREMENTAL:NO) /OPT:REF is selected /OPT:ICF is selected

waruqi commented 7 months ago

Found the issue, adding this flag fixes it. image

you can try debug mode. xmake f -m debug; xmake ; xmake run

Lyuu17 commented 7 months ago

Found the issue, adding this flag fixes it. image

you can try debug mode. xmake f -m debug; xmake ; xmake run

I'm having some issues building with debug mode, they're building with MT instead of MTd runtime in debug mode, same with tests

SirLynix commented 7 months ago

Try set_runtimes(is_mode("debug") and "MDd" or "MD")

Lyuu17 commented 7 months ago

Try set_runtimes(is_mode("debug") and "MDd" or "MD")

thanks, it works

now i have made a a clean build and seems like /incremental doesn't fix anything, probably it's a wxwidgets linking issue (i rewrote the script to build as static)