用GCC编译WIN32代码

发布于 2024-10-08 10:09:45 字数 341 浏览 3 评论 0原文

我尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹿港小镇 2024-10-15 10:09:45

尝试在命令提示符下编译,看看会发生什么。

对于您的资源文件,请在命令提示符中尝试此操作。

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

堇年纸鸢 2024-10-15 10:09:45

我尝试编译一些C++ WIN32
通过 DevC++ (MinGW
海湾合作委员会)。貌似链接失败
这些物体并没有给我一个
清除错误消息:“[PathToSource] >
错误1”。

您是否包含了 Windows SDK 的路径?在我的计算机上,它位于:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64

(注意我的计算机上安装了 Visual Studios)

使用适当的 gcc 库设置

用 Eclipse 尝试过同样的事情
(MinGW GCC)并编译。然而,
并非所有资源都像我一样显示
有一个图标设置为编译
应用程序的图标,已加载
从资源文件中。我也得到一个
控制台窗口在后台,就像我一样
运行应用程序。

检查资源设置以查看 Eclipse 在何处引用您的 Windows 库。

这是什么原因呢?我怎样才能
使资源文件编译为
代码并避免加载
后台的控制台窗口。

在 Visual Studio 中开发您的应用程序。如果您买不起 Visual Studio 并且您是一个业余爱好项目,请考虑 Visual Studios Express< /a>.

我也想知道有没有办法
通过以下方式在 Linux 中编译 WIN32 代码
GCC,或者一种移植它的方法
编译器。

如果您指的是 WINAPI,那么不,据我所知不是。如果您想要兼容性,您应该坚持使用标准 C++ 库。

但是,您可能会发现一些有用的通用库:

  1. http://sourceware.org/pthreads-win32/
  2. http://stdcxx.apache.org/#platforms
  3. http://www.gtk.org/download-windows.html
  4. 跨平台库 (Stackoverflow)

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".

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.

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.

Check the resource settings to see where Eclipse is referencing your Windows Library.

What is the couse 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.

Develop your applications in Visual Studio. If you cannot afford Visual Studio and you are a hobby programm consider Visual Studios Express.

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.

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:

  1. http://sourceware.org/pthreads-win32/
  2. http://stdcxx.apache.org/#platforms
  3. http://www.gtk.org/download-windows.html
  4. Cross Platform Lbiraries (Stackoverflow)
回忆追雨的时光 2024-10-15 10:09:45

Eclipse 中的资源文件:

在项目的构建步骤中,需要输入命令以及资源及其输出文件的完整路径。

windres ../Resources/resource_file.rc -o ../Debug/resource_file.o

在项目的工具设置链接器选项中,需要添加资源输出文件的路径,以便将资源链接到可执行文件中。

../Debug/resource_file.o

避免控制台窗口:

仅需要为 GUI 指定链接器标志。

-mwindows

在 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.

windres ../Resources/resource_file.rc -o ../Debug/resource_file.o

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.

../Debug/resource_file.o

Avoid the console window:

A linker flag needs to be specified for GUI only.

-mwindows

In Eclipse:

Enter the flag in the project Tool Settings in Linker flags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文