用GCC编译WIN32代码
我尝试通过 DevC++ (MinGW GCC) 使用 GCC 编译一些 C++ WIN32 代码。它似乎无法链接对象,并且没有给我明确的错误消息:“[PathToSource] > Error 1”。
用 Eclipse (MinGW GCC) 尝试了同样的事情并编译了。但是,并非所有资源都显示,因为我有一个图标设置为编译为应用程序的图标,它是从资源文件加载的。当我运行应用程序时,我还会在后台看到一个控制台窗口。
这是什么原因呢?如何使资源文件与代码一起编译,并避免在后台加载控制台窗口。
我还想知道是否有一种方法可以通过 GCC 在 Linux 中编译 WIN32 代码,或者可以将其移植到同一编译器。
I have tried to compile some C++ WIN32 code with GCC through DevC++ (MinGW GCC). It seams that it failed to link the objects and it didn't give me a clear error message: "[PathToSource] > Error 1".
Tried the same thing with Eclipse (MinGW GCC) and it compiled. However, not all of the resources show as I have an icon set to compile as the icon of the application, it's loaded from the resource files. I also get a console window in the background as I run the application.
What is the cause of this? How can I make the resource files compile with the code and also avoid the loading of a console window in the background.
I was also wondering if there's a way to compile WIN32 code in Linux through GCC, or a way to port it for the same compiler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在命令提示符下编译,看看会发生什么。
对于您的资源文件,请在命令提示符中尝试此操作。
windres resource_file.rc -o resource_file.o
最后构建代码,g++ resource_file.o -o app.exe app.cpp
Try compiling in command prompt and see what happens.
for your resource file try this in the command prompt.
windres resource_file.rc -o resource_file.o
and finally to build your code,g++ resource_file.o -o app.exe app.cpp
您是否包含了 Windows SDK 的路径?在我的计算机上,它位于:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64
(注意我的计算机上安装了 Visual Studios)
使用适当的 gcc 库设置。
检查资源设置以查看 Eclipse 在何处引用您的 Windows 库。
在 Visual Studio 中开发您的应用程序。如果您买不起 Visual Studio 并且您是一个业余爱好项目,请考虑 Visual Studios Express< /a>.
如果您指的是 WINAPI,那么不,据我所知不是。如果您想要兼容性,您应该坚持使用标准 C++ 库。
但是,您可能会发现一些有用的通用库:
Have you included a path to the Windows SDK? On my computer it is at:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64
(Note I have Visual Studios Installed on my Computer)
Compile you program with the appropriate gcc library settings.
Check the resource settings to see where Eclipse is referencing your Windows Library.
Develop your applications in Visual Studio. If you cannot afford Visual Studio and you are a hobby programm consider Visual Studios Express.
If you mean the WINAPI, then no, not as far as I know. If you want compatibility you should stick with the standard C++ library.
There are, however, universal libraries that you might find useful:
Eclipse 中的资源文件:
在项目的构建步骤中,需要输入命令以及资源及其输出文件的完整路径。
在项目的工具设置链接器选项中,需要添加资源输出文件的路径,以便将资源链接到可执行文件中。
避免控制台窗口:
仅需要为 GUI 指定链接器标志。
在 Eclipse 中:
在链接器标志中的项目工具设置中输入标志。
Resource files in Eclipse:
In the Build Steps of the project, there needs to be entered the command and the full path to the resource and its output file.
In the Tool Settings of the project in the linker options, the path to the resource output file needs to be added in order for the resources to be linked into the executable file.
Avoid the console window:
A linker flag needs to be specified for GUI only.
In Eclipse:
Enter the flag in the project Tool Settings in Linker flags.