如何修复介子生成不正确的链接器标志(-子系统控制台) [英] How to fix meson generating an incorrect linker flag (--subsystem console)
问题描述
我创建了一个简单的项目来使自己习惯介子,但是构建始终失败.
I've created a simple project to get myself accustomed to meson, but the build keeps failing.
这就是我所做的(设置环境和构建):
This is what I did (to set up the environment, and to build):
set CC=clang
set CC_LD=lld
set CFLAGS="--target x86_64-pc-windows-msvc"
meson build
cd build
ninja
我的 meson.build
如下:
project('EtaClient', 'c')
src = ['src/main.c', 'src/linkedlist.c']
executable('EtaClient', src)
target = 'x86_64-pc-windows-msvc'
在构建时,出现以下错误(obj文件已成功构建,但未链接,因此未构建exe):
While building, I get the following errors (the obj files are built successfully, but they're not linked and thus the exe isn't built):
LINK : warning LNK4044: unrecognized option '/-subsystem'; ignored
LINK : fatal error LNK1181: cannot open input file 'console.obj'
clang: error: linker command failed with exit code 1181 (use -v to see invocation)
当我查看 build.ninja
以查看发生了什么时,我发现:
When I look in my build.ninja
to see what's going on, I find:
build EtaClient.exe | EtaClient.pdb: c_LINKER EtaClient.exe.p/src_main.c.obj EtaClient.exe.p/src_linkedlist.c.obj
LINK_ARGS = "-Wl,/nologo" "-Wl,/release" "-Wl,/nologo" "-Wl,/DEBUG" "-Wl,/PDB:EtaClient.pdb" "-Wl,--subsystem,console" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32"
我将-Wl,-subsystem,console"
替换为-Wl,/subsystem:console"
,并且构建成功编译,但是我每次我修改 meson.build
时,都必须手动进行此编辑.
I replace "-Wl,--subsystem,console"
with "-Wl,/subsystem:console"
, and the build compiles successfully, but I have to manually make this edit each time I modify my meson.build
.
有人可以告诉我为什么会这样,以及如何设置介子以生成正确的标志吗?预先感谢.
Could someone tell me why this happens, and how to set up meson to generate the correct flag? Thanks in advance.
推荐答案
在Windows上时,请使用clang-cl而不是clang并忽略链接程序的定义
use clang-cl instead of clang and leave out the defintion of the linker when you are on windows
set CC=clang-cl
set CFLAGS="--target x86_64-pc-windows-msvc"
meson build
cd build
ninja
请参阅 https://github.com/mesonbuild/meson/issues/4232
这篇关于如何修复介子生成不正确的链接器标志(-子系统控制台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!