G ++包含来自cmd的.rc文件 [英] G++ include .rc files from cmd

查看:65
本文介绍了G ++包含来自cmd的.rc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用资源(.rc文件)制作了一个简单的WIN32项目.

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

当我用code :: block编译时,对话框显示,但是从cmd用g ++编译时却没有.

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

尝试将.rc作为g ++的参数包括在内,结果如下:
main.rc:无法识别文件:无法识别文件格式collect2.exe:错误:ld返回1退出状态

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

如何将.rc文件包含到cmd中的g ++中?

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

我尝试用windres做:
windres main.rc -o res.o
g ++ -c win_main.cpp resource.h -o source.o
g ++ -o可执行res.o source.o

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

我遇到了相同的错误,但是没有识别出 main.o 而不是 main.rc .

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

推荐答案

MS资源工具与GNU工具之间的主要区别在于,MS RC会以特殊的二进制资源格式生成'.res'文件,该文件可以直接传递给MS链接,而GNU链接器LD仅支持".o"(与".obj"相同)格式.因此,作为@SoronelHaetir的答案,您需要使用windres: windres main.rc -o res.o

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

我还要指出的是,您不应该编译" .h文件.这样做将创建不用于创建可执行文件的预编译头文件,然后导致 xxx.o:无法识别文件:无法识别文件格式.由于#include指令,Builder能够自行找到这些头文件.请参见此处.

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.

这篇关于G ++包含来自cmd的.rc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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