简体   繁体   English

G ++包含来自cmd的.rc文件

[英]G++ include .rc files from cmd

I've made a simple WIN32 project using resources (.rc files). 我已经使用资源(.rc文件)制作了一个简单的WIN32项目。

When I compile with code::blocks the dialog box displays, but when compiling with g++ from cmd it doesn't. 当我使用code :: blocks进行编译时,将显示对话框,但是当使用cmd中的g ++进行编译时,则不会。

Trying to include the .rc as an argument to g++ results in this: 尝试将.rc作为g ++的参数包括在内,结果如下:
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? 如何在cmd中将.rc文件包含到g ++中?

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. 我收到相同的错误,但无法识别main.o而不是main.rc

.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. .rc文件不提供给gcc,它们必须由windres处理(MS的rc.exe的gcc等效),您可以使用windres从.rc创建.o文件,然后将.o提供给gcc (或ld)作为您最终链接阶段的一部分。

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. 有其他潜在的论据,请查看手册页以获取详细信息。

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. MS资源工具和GNU工具之间的主要区别在于,MS RC以特殊的二进制资源格式生成“ .res”文件,可以将其直接传递给MS链接,而GNU链接器LD仅支持“ .o”(与'.obj')格式。 So As the answer of @SoronelHaetir, you need to use the windres: windres main.rc -o res.o 因此,作为@SoronelHaetir的答案,您需要使用windres: windres main.rc -o res.o

What else I want to point out is You shouldn't "compile" .h files. 我还要指出的是,您不应该“编译” .h文件。 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 . 这样做将创建不用于创建可执行文件的预编译头文件,然后导致xxx.o: file not recognized: File format not recognized Builder is able to find these header files by itself due to #include directives. 由于#include指令,Builder能够自行找到这些头文件。 See the similar issue here . 这里看到类似的问题。

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

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