简体   繁体   English

如何用MinGWwindres编译资源文件?

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

My ultimate goal is to set the version(that shows in properties->details) of an executable being compiled with MinGW gcc-g++.我的最终目标是设置正在使用 MinGW gcc-g++ 编译的可执行文件的版本(显示在 properties->details 中)。 But for now I would like to compile a resource file with windres to be able to link it later manually.但是现在我想用windres编译一个资源文件,以便以后能够手动链接它。 But I got following error, when I use this command: windres resource.rc -o resource.res :但是当我使用此命令时出现以下错误: 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.

My resource.rc looks like this:我的 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
    }
}

and my resource.h is just empty, maybe that is the problem?而我的 resource.h 只是空的,也许这就是问题所在? It amazes me how complicated it is to simply set the version number in the property tab in an exe.让我惊讶的是,在 exe 的属性选项卡中简单地设置版本号是多么复杂。 I've been reading a lot of other SO answers but none of them worked for me.我一直在阅读很多其他的 SO 答案,但没有一个对我有用。 For eg this one seems too ambiguous on how to exactly proceed after having this resource.rc file.对于如这一个似乎对如何具有这种RESOURCE.RC文件后,究竟进行得模棱两可。

As a resource compiler windres does not know the constants found in your file so you need to provide those, which is commonly done via the includes.作为资源编译器, windres不知道在您的文件中找到的常量,因此您需要提供这些常量,这通常通过包含来完成。
The easiest thing is to adjust the header of your file to the following:最简单的方法是将文件的标题调整为以下内容:

#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 */

As you want to compile/link with gcc you want windres to output an object file, otherwise you won't be able to link it later.由于您想用 gcc 编译/链接,您希望windres 输出一个目标文件,否则您以后将无法链接它。 To fix that change the compile command to windres resource.rc -o resource.o .要解决该问题,请将 compile 命令更改为windres resource.rc -o resource.o

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

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