FFWD to 2020 Q4. In the era of VS Code
, a lot of people are somewhat struggling with "beyond the basics" when trying to compile WIN32 GUI "Hello World" without Visual Studio. And yes, the resource file is probably the main stumbling block. That is a wider subject.
由于问题只是关于如何“编织”弧卷的问题,请允许我仅回答这个问题。
下面请看一下你还有<编码>my_app.rc和resource.h
。
- to avoid some potential big hassle make sure you have
#include <windows.h>
at the top of the rc
file
- resource compiler is called
rc
. If cl.exe
is on the path, rc.exe
is too.
rc
makes a binary res
file from the rc
file.
rc my_app.rc
will produce my_app.res
- of course only if your rc file has no mistakes in there.
- if
rc
can not find windows.h
you can add the path to it like so
rc /i"C:Windows Kits10Include10.0.18362.0um" my_app.rc
- with your local path of course.
- to use the
res
, on the cl
command line you need to pass the res
file to the linker, like on this imaginary example cl compilation command line
cl /Zi /EHsc /Fe:my_app.exe my_app.cpp /link my_app.res
确保<条码>/link是<条码>的最后一个论点。
http://www.ohchr.org。
让我们承担项目内容:
my_app.cpp
resource.h
my_app.rc
First, you will need to produce my_app.res
as described above.
Second, in the VS Code .vscode/tasks.json
, you will have:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\${fileBasenameNoExtension}.exe",
"${file}",
"/link /SUBSYSTEM:WINDOWS ${fileDirname}\${fileBasenameNoExtension}.res",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: cl.exe"
}
]
}
通知<代码>/link 您需要在生成的其他标准任务档案中添加这一论点。 开放式<代码>my_app.cpp 并CTRL+SHIFT+B
。 这将汇编并链接到您的WIN32 App,包括你们的资源。