删除 Glut/FreeGlut/GLFW 的控制台窗口?

发布于 2024-11-06 17:56:48 字数 524 浏览 11 评论 0原文

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

  • Error 2 fatal error LNK1120: 1
    unresolved externals glfwWindow.exe

Is it possible to remove the console window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(9

蓝眼泪 2024-11-13 17:56:49

当我遇到这样的错误时,我可以通过在链接器高级部分、选项入口点中输入以下文本来修复它> 以下内容:

主要内容

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:

main

寂寞花火° 2024-11-13 17:56:49

以下是如何在 Visual Studio 下解决该问题而无需重写代码的详细说明:

  1. 打开项目属性窗口,
  2. 保留调试配置不变,控制台非常适合调试
  3. 发布配置下,转到链接器->所有选项
  4. 入口点设置为ma​​inCRTStartup
  5. 设置<强>子系统到Windows: /SUBSYSTEM:WINDOWS
  6. 点击应用保存设置

现在,当您在调试配置下编译项目时,会出现控制台窗口,而在 < code>Release 配置它永远不会打开。您可以以任何常见形式使用入口点函数:

int main() {}

int main(int argc, char** argv) {}

我个人更喜欢第二种。感谢 Chaoelmindreda< /a>,我给你们投了票!

Here is the detailed instruction how to solve it under Visual Studio without rewriting your code:

  1. Open project Properties window
  2. Leave the Debug configuration as is, console is great for debugging
  3. Under Release configuration go to Linker->All Options
  4. Set Entry Point to mainCRTStartup
  5. Set SubSystem to Windows: /SUBSYSTEM:WINDOWS
  6. Hit Apply to save setting

Now when you compile your project under Debug configuration, the console window appears, while under Release configuration it never opens. You can use the entry point function in any common forms:

int main() {}

int main(int argc, char** argv) {}

I personally prefer the second. Thanks to Chao and elmindreda, I upvoted you guys!

不离久伴 2024-11-13 17:56:48

在链接器选项下,将入口点设置为 ma​​inCRTStartup 。该函数对 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.

涫野音 2024-11-13 17:56:48

我的项目只有一个 main,(没有 WinMain),要禁用控制台,我只需将 Linker->System->SubSystem 设置为“Windows (/ SUBSYSTEM:WINDOWS)”而不是“Console (/SUBSYSTEM:CONSOLE)”,控制台就会消失。

您不需要弄乱预处理器定义来删除控制台窗口。

我知道我的回答晚了几年,但我希望它能有所帮助。

My project just has a main, (no WinMain) 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.

蓝咒 2024-11-13 17:56:48

大多数链接器支持自动删除控制台启动代码的选项。

我认为在 GCC 上它被称为 -mwindows

Most linkers support options that automatically remove the console startup code.

I think on GCC it's called -mwindows

南风起 2024-11-13 17:56:48

要使用 cmake 摆脱控制台,可以按如下方式设置链接标志:

set_target_properties(exe_name PROPERTIES 
    LINK_FLAGS "/ENTRY:mainCRTStartup /SUBSYSTEM:WINDOWS")

To get rid of the console using cmake, the link flags can be set as follows:

set_target_properties(exe_name PROPERTIES 
    LINK_FLAGS "/ENTRY:mainCRTStartup /SUBSYSTEM:WINDOWS")
┾廆蒐ゝ 2024-11-13 17:56:48

非控制台 Windows 应用程序使用 WinMain() 入口点约定。您的 Glut 示例可能使用标准 C main() 约定。

如果您只想快速修复演示应用程序,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 C main() 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

相对绾红妆 2024-11-13 17:56:48

您需要编写一个 WinMain 入口点并复制现有代码(来自 main):

int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
){
    // ...
}

You need to write a WinMain entry point and copy your existing code (from main):

int CALLBACK WinMain(
  __in  HINSTANCE hInstance,
  __in  HINSTANCE hPrevInstance,
  __in  LPSTR lpCmdLine,
  __in  int nCmdShow
){
    // ...
}
苍景流年 2024-11-13 17:56:48

如果您创建一个新项目作为控制台应用程序,它将始终这样运行。如果您想在实际窗口中运行它,您必须创建一个新的 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.

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