如何使用MinGW Windres编译资源文件?

问题描述 投票:0回答:1

我的最终目标是设置使用 MinGW gcc-g++ 编译的可执行文件的版本(在属性 -> 详细信息中显示)。但现在我想用 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 的属性选项卡中设置版本号是多么复杂。我读过很多其他的答案,但没有一个对我有用。例如这个对于在拥有这个resource.rc文件后如何准确地进行似乎太模糊了。

windows mingw mingw32
1个回答
0
投票

作为资源编译器

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输出一个目标文件,否则你以后将无法链接它。 要解决此问题,请将编译命令更改为

windres resource.rc -o resource.o

© www.soinside.com 2019 - 2024. All rights reserved.