删除 Glut/FreeGlut/GLFW 的控制台窗口?
在 Visual C++ 下,我尝试过 Glut/FreeGlut/GLFW。似乎所有这些项目都默认添加了一个 CMD 窗口。我尝试将其删除:
属性->C/C++->预处理器->预处理器 定义
从这里,我删除了 _CONSOLE 并将其替换为 _WINDOWS
然后我进入:
属性->链接器->系统->子系统
我将选项设置为 Windows (/SUBSYSTEM:WINDOWS)
然后当我尝试在 GLFW 下编译时,出现以下构建错误:
Error 1 error LNK2001: unresolved 外部符号_WinMain@16 MSVCRT.lib
错误 2 致命错误 LNK1120: 1 无法解析的外部 glfwWindow.exe
是否可以删除控制台窗口?
Under Visual C++, I have played around with Glut/FreeGlut/GLFW. It seems that everyone of these projects adds a CMD window by default. I tried removing it going under:
Properties->C/C++->Preprocessor->Preprocessor
Definitions
From here, I remove the _CONSOLE and replace it with _WINDOWS
Then I went under:
Properties->Linker->System->SubSystem
And I set the option to Windows (/SUBSYSTEM:WINDOWS)
Then when I try compiling under GLFW, I get the following building errors:
Error 1 error LNK2001: unresolved
external symbol _WinMain@16
MSVCRT.libError 2 fatal error LNK1120: 1
unresolved externals glfwWindow.exe
Is it possible to remove the console window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
当我遇到这样的错误时,我可以通过在链接器、高级部分、选项入口点中输入以下文本来修复它> 以下内容:
When I've gotten an error like that I was able to fix it by entering that following text in the linker, section Advance, option Entry Point the following:
以下是如何在
Visual Studio
下解决该问题而无需重写代码的详细说明:现在,当您在
调试
配置下编译项目时,会出现控制台窗口,而在 < code>Release 配置它永远不会打开。您可以以任何常见形式使用入口点函数:我个人更喜欢第二种。感谢 Chao 和 elmindreda< /a>,我给你们投了票!
Here is the detailed instruction how to solve it under
Visual Studio
without rewriting your code:Now when you compile your project under
Debug
configuration, the console window appears, while underRelease
configuration it never opens. You can use the entry point function in any common forms:I personally prefer the second. Thanks to Chao and elmindreda, I upvoted you guys!
在链接器选项下,将入口点设置为 mainCRTStartup 。该函数对 MS libc 进行必要的设置,然后调用 main。
Under the linker options, set your entry point to mainCRTStartup . This function does the necessary setup of the MS libc and then calls main.
我的项目只有一个
main
,(没有WinMain
),要禁用控制台,我只需将 Linker->System->SubSystem 设置为“Windows (/ SUBSYSTEM:WINDOWS)
”而不是“Console (/SUBSYSTEM:CONSOLE)
”,控制台就会消失。您不需要弄乱预处理器定义来删除控制台窗口。
我知道我的回答晚了几年,但我希望它能有所帮助。
My project just has a
main
, (noWinMain
) and to disable console, I just set Linker->System->SubSystem to "Windows (/SUBSYSTEM:WINDOWS)
" instead of "Console (/SUBSYSTEM:CONSOLE)
" and the console goes away.You don't need to mess with the Preprocessor Definitions to remove the console window.
I know my answer is a few years late, but I hope it helps.
大多数链接器支持自动删除控制台启动代码的选项。
我认为在 GCC 上它被称为 -mwindows
Most linkers support options that automatically remove the console startup code.
I think on GCC it's called -mwindows
要使用 cmake 摆脱控制台,可以按如下方式设置链接标志:
To get rid of the console using cmake, the link flags can be set as follows:
非控制台 Windows 应用程序使用
WinMain()
入口点约定。您的 Glut 示例可能使用标准 Cmain()
约定。如果您只想快速修复演示应用程序,WinAPI 函数
FreeConsole()
可能会有所帮助。MSDN:http://msdn.microsoft.com/en-us/library /ms683150(v=vs.85).aspx
Non-console Windows applications use the
WinMain()
entry point convention. Your Glut examples probably use the standard Cmain()
convention.If you want a quick fix just for the demo app, the WinAPI function
FreeConsole()
might help.MSDN: http://msdn.microsoft.com/en-us/library/ms683150(v=vs.85).aspx
您需要编写一个
WinMain
入口点并复制现有代码(来自main
):You need to write a
WinMain
entry point and copy your existing code (frommain
):如果您创建一个新项目作为控制台应用程序,它将始终这样运行。如果您想在实际窗口中运行它,您必须创建一个新的 GUI 项目,否则将不会包含正确的标头和库。
此外,所需的 WinMain 函数也将包含在生成的模板文件中。
If you create a new project as a console application, it will always run as such. You have to create a new GUI project if you want to run it in an actual window, otherwise the correct headers and libraries will not be included.
Also the WinMain function that's required will be included for you in the resulting template files.