简体   繁体   中英

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++. 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.

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
    }
}

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 eg this one seems too ambiguous on how to exactly proceed after having this resource.rc file.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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