繁体   English   中英

如何用MinGWwindres编译资源文件?

[英]How to compile resource file with MinGW windres?

我的最终目标是设置正在使用 MinGW gcc-g++ 编译的可执行文件的版本(显示在 properties->details 中)。 但是现在我想用windres编译一个资源文件,以便以后能够手动链接它。 但是当我使用此命令时出现以下错误: windres resource.rc -o resource.res

windres: resource.rc:2: syntax error
The process tried to write to a nonexistent pipe.
...
The process tried to write to a nonexistent pipe.
resource.rc:4:0: fatal error: when writing output to : Invalid argument
VS_VERSION_INFO VERSIONINFO

compilation terminated.
windres: preprocessing failed.

我的 resource.rc 看起来像这样:

#include "winver.h"

#include "../include/resource.h"
VS_VERSION_INFO VERSIONINFO
 FILEVERSION    0,0,0,2
 PRODUCTVERSION 0,0,0,2
 FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
 FILEFLAGS 0x1L
 #else
 FILEFLAGS 0x0L
 #endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
{
    BLOCK "StringFileInfo"
    {
        BLOCK "040904b0"
        {
            VALUE "Comments",         "comment\0"
            VALUE "CompanyName",      "comment\0"
            VALUE "FileDescription",  "base file\0"
            VALUE "FileVersion",      "0.0.0.2 TP\0"
            VALUE "InternalName",     "testTP\0"
            VALUE "LegalCopyright",   "none\0"
            VALUE "OriginalFilename", "test.exe\0"
            VALUE "ProductName",      "test\0"
            VALUE "ProductVersion",   "0.0.0.2 TP\0"
        }
    }
    BLOCK "VarFileInfo"
    {
        VALUE "Translation", 0x409, 1200
    }
}

而我的 resource.h 只是空的,也许这就是问题所在? 让我惊讶的是,在 exe 的属性选项卡中简单地设置版本号是多么复杂。 我一直在阅读很多其他的 SO 答案,但没有一个对我有用。 对于如这一个似乎对如何具有这种RESOURCE.RC文件后,究竟进行得模棱两可。

作为资源编译器, windres不知道在您的文件中找到的常量,因此您需要提供这些常量,这通常通过包含来完成。
最简单的方法是将文件的标题调整为以下内容:

#include <windows.h>

VS_VERSION_INFO VERSIONINFO
 FILEVERSION    0,0,0,2
 PRODUCTVERSION 0,0,0,2
 FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
 FILEFLAGS 0x1L
 #else
 FILEFLAGS 0x0L
 #endif

 /* rest follows */

由于您想用 gcc 编译/链接,您希望windres 输出一个目标文件,否则您以后将无法链接它。 要解决该问题,请将 compile 命令更改为windres resource.rc -o resource.o

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM