通过命令行使用 gcc 编译 win32 应用程序时如何链接 .rc(资源)文件?
我一直在关注伪造者 win32 教程,特别是 此 部分,并且是想知道在编译 win32 程序时如何链接 .rc(资源)文件? (我正在通过命令行编译)。
我正在阅读这篇文章,其中说你可以做这样的事情windres Chocolate-doom- res.rc Chocolate-doom-res.o
并以这种方式编译gcc other.o files.o etc.o Chocolate-doom-res.o -o Chocolate-doom.exe
但是当我尝试执行 windres res.rc res.o
(res.rc 是我的资源文件)时,它给了我这个 windres: res.rc:3: 语法错误
res。 rc
#include "resource.h"
IDR_MYMENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else",0,GRAYED
END
END
IDI_MYICON ICON "menu_one.ico"
有什么想法吗?
I have been following the forgers win32 tutorial, specifically this section as of this moment, and was wondering how you would link the .rc(resource) file when compiling a win32 program? (I'm compiling through command line).
I was reading this article which says you could do something like this windres chocolate-doom-res.rc chocolate-doom-res.o
and compile this waygcc other.o files.o etc.o chocolate-doom-res.o -o chocolate-doom.exe
But when I tried doing windres res.rc res.o
(res.rc is my resource file) it gives me this windres: res.rc:3: syntax error
res.rc
#include "resource.h"
IDR_MYMENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else",0,GRAYED
END
END
IDI_MYICON ICON "menu_one.ico"
Any ideas?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您缺少 MENU 资源类型。你应该写:
You're missing the MENU resource type. You should write:
FFWD 至 2020 年第四季度。在
VS Code
时代,很多人在尝试在没有Visual Studio的情况下编译WIN32 GUI“Hello World”时都有些“超越基础”的挣扎。是的,资源文件可能是主要的绊脚石。这是一个更广泛的主题。由于问题只是关于如何“编译”rc 文件,所以我只回答这个问题。
不知何故,您已经拥有了
my_app.rc
和resource.h
。rc
文件顶部有#include
rc
。如果cl.exe
位于路径上,则rc.exe
也在路径上。rc
从rc
文件创建二进制res
文件。rc my_app.rc
将生成my_app.res
rc
找不到windows.h
你可以像这样添加它的路径rc /i"C:\Windows Kits\10\Include\10.0.18362.0\um" my_app.rc
res
,在cl
命令行上,您需要将res
文件传递给链接器,就像这个虚构的示例 cl 编译命令一样确保/link
是cl
命令行的最后一个参数。编辑
假设您的项目文件夹包含:
首先,您需要如上所述生成
my_app.res
。其次,在 VS Code
.vscode/tasks.json
中,您将拥有:注意您需要添加到由 < 生成的其他标准任务文件中的
/link
参数。代码>VS代码。打开my_app.cpp
并执行CTRL+SHIFT+B
。这将编译活动文件并将其链接到您的 WIN32 应用程序中,其中包括您的资源。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.Since the question is only about how to "compile in" the rc file, let me answer only that.
Somehow you got to the point at which you also have
my_app.rc
andresource.h
.#include <windows.h>
at the top of therc
filerc
. Ifcl.exe
is on the path,rc.exe
is too.rc
makes a binaryres
file from therc
file.rc my_app.rc
will producemy_app.res
rc
can not findwindows.h
you can add the path to it like sorc /i"C:\Windows Kits\10\Include\10.0.18362.0\um" my_app.rc
res
, on thecl
command line you need to pass theres
file to the linker, like on this imaginary example cl compilation command linemake sure
/link
is the last argument to yourcl
command line.EDIT
Let's assume your project folder contains:
First, you will need to produce
my_app.res
as described above.Second, in the VS Code
.vscode/tasks.json
, you will have:Notice the
/link
argument you need to add, to the otherwise standard tasks file generated byVS Code
. Openmy_app.cpp
and performCTRL+SHIFT+B
. That will compile and link the active file into your WIN32 App, with your resources included.