0

I've made a simple WIN32 project using resources (.rc files).

When I compile with code::blocks the dialog box displays, but when compiling with g++ from cmd it doesn't.

Trying to include the .rc as an argument to g++ results in this:
main.rc: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status

How do I include the .rc file to g++ in cmd?

Edit: I tried with windres doing:
windres main.rc -o res.o
g++ -c win_main.cpp resource.h -o source.o
g++ -o Executable res.o source.o

I get the same error but with main.o instead of main.rc not recognized.

snzm
  • 139
  • 1
  • 1
  • 10

2 Answers2

1

.rc files aren't fed to gcc, they have to be processed by windres (the gcc equivalent of MS' rc.exe), you use windres to create a .o file from the .rc and then feed that .o to gcc (or ld) as part of your final link stage.

windres my_file.rc my_file.o
gcc -o my_final <other parameters> my_file.o

There are other potential arguments to windres, look at the man page for details.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
0

The main difference between MS resource tools and GNU tools is that MS RC generates'.res' files in a special binary resource format, which can be passed directly to MS links, while GNU linker LD only supports '.o' (the same as'.obj') format. So As the answer of @SoronelHaetir, you need to use the windres: windres main.rc -o res.o

What else I want to point out is You shouldn't "compile" .h files. Doing so will create precompiled header files, which are not used to create an executable, then cause the xxx.o: file not recognized: File format not recognized. Builder is able to find these header files by itself due to #include directives. See the similar issue here.

Drake Wu
  • 6,927
  • 1
  • 7
  • 30