qrani
qrani

Reputation: 67

When Compiling With .RES File with MinGW G++, .RES isn't Recognized

I've been trying to compile a program that will have an icon linked with it, on Windows. Based off of my recent research, since I've never done this before, You would make a .RC file with the info of the program, including icons, which you would then use windres to turn it into a .RES file, which you would then link when compiling:

g++ program.cpp -o program.exe

would become

g++ program.cpp program.res -o program.exe

I'm guessing this is the right way to do it, but I'm not sure because when I try to compile the program, it gives the error:

program.res: file not recognized: file format not recognized
collect2.exe error: ld returned 1 exit status

What can I do to fix this? I've seen people say that if you're compiling 32-bit programs, which I believe I am, you can add parameters to turn it into a .RES file that is meant for compiling 32-bit programs. I've tried this but, it gave the exact same issue, so I don't think that that is the problem.

Upvotes: 5

Views: 2299

Answers (2)

emlo40
emlo40

Reputation: 91

Add coff when making the .res

windres my.rc -O coff my.res

That's gonna save the .res in a usable format.

I base this on the use of it in a stack overflow post and a quick wiki search. Also, I had the same issue and adding coff fixed it. links: https://stackoverflow.com/a/708382 https://en.wikipedia.org/wiki/COFF

Upvotes: 9

janos_
janos_

Reputation: 51

So on windows you can use the Visual Studio Developer-Powershell.

Create a .rc file (create a .txt file and change the extension).

my.rc

iconName ICON "path_to_icon.ico"

Compile my.rc to my.rcs.

rc my.rc

Now you want to link that against your executable. But you cant do that with the .rcs file. You have to convert it with "cvtres" first.

cvtres /MACHINE:x64 my.res

This results in a file called "my.obj". This file can now be linked when calling g++, for example, just like done above in the question.

Source: https://learn.microsoft.com/en-us/windows/win32/menurc/renaming-the-compiled-resource-file

CVTRES must then be invoked to convert the .res file to a binary resource (.rbj) format which can be understood by the linker.

More on the resource compiler included in Visual Studio: https://learn.microsoft.com/en-us/windows/win32/menurc/resource-compiler

Cheers

Upvotes: 0

Related Questions