Removing console window for Glut/FreeGlut/GLFW?

痞子三分冷 提交于 2020-06-09 10:27:30

问题


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?


回答1:


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




回答2:


Under the linker options, set your entry point to mainCRTStartup . This function does the necessary setup of the MS libc and then calls main.




回答3:


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.




回答4:


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

I think on GCC it's called -mwindows




回答5:


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
){
    // ...
}



回答6:


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



回答7:


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.




回答8:


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



来源:https://stackoverflow.com/questions/5995433/removing-console-window-for-glut-freeglut-glfw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!