Why does the windows command prompt open whenever I run my OpenGL program?
2 Answers
This is nothing specific with OpenGL, but with the framework you use. Most likely you're using GLUT, for which the tutorials use the program entry function main
. The default subsystem for programs using main
(in contrast to WinMain
) opens a console window when started. You can get rid of it using the method I showed in https://stackoverflow.com/a/6882500/524368
If you're using Visual C++ in the project build linker options set
/SUBSYSTEM:windows
/ENTRY:mainCRTStartup
Or use the following #pragma in the source file with the int main(...)
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
If using a GNU toolchain use the following additional linker flags to set the subsystem. No need to change the entry function.
LDFLAGS += --subsystem windows
-
When I compile my program, it says: "warning: ignoring pragma comment [-Wunknown-pragmas]" – Jake Sumrican Apr 13 '13 at 19:13
-
@JakeSumrican: Let me guess: You're not using Visual C++? Sorry, I should have added, that the instructions were specific to Microsoft's toolchain. In case you're using a GNU toolchain you must use linker options. See my answer update, I'll add in a moment. – datenwolf Apr 13 '13 at 19:16
This is a Visual Studio linker configuration setting that can be modified.
In order to disable the console window from appearing during your application's run-time, do the following:
- Right-click the project
- Go to Properties -> Linker -> System ->SubSystem setting
- Ensure that "Windows" is selected and not "Console".

- 18,263
- 13
- 58
- 79

- 1
- 1