如何用MinGWwindres编译资源文件? [英] How to compile resource file with MinGW windres?

查看:96
本文介绍了如何用MinGWwindres编译资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My ultimate goal is to set the version(that shows in properties->details) of an executable being compiled with MinGW gcc-g++. But for now I would like to compile a resource file with windres to be able to link it later manually. But I got following error, when I use this command: 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 如下所示:

My resource.rc looks like this:

#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 答案,但没有一个对我有用.例如这个在拥有此资源后如何准确进行似乎过于模糊.rc 文件.

and my resource.h is just empty, maybe that is the problem? It amazes me how complicated it is to simply set the version number in the property tab in an exe. I've been reading a lot of other SO answers but none of them worked for me. For e.g. this one seems too ambiguous on how to exactly proceed after having this resource.rc file.

推荐答案

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

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

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

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. To fix that change the compile command to windres resource.rc -o resource.o.

这篇关于如何用MinGWwindres编译资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆