1

How do I setup my project so that it opens a window instead of console?

#include <GL\glew.h>
#include <GL\glfw.h>

int main()
{
    glfwInit();
    glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
    glfwTerminate();
    return 0;
}

This code opens a window but it also opens a console, how do setup my project so that only window appear? Using VS 2010.

user2672165
  • 2,910
  • 17
  • 26
codekiddy
  • 5,527
  • 9
  • 48
  • 79

2 Answers2

2

See my answer here: https://stackoverflow.com/a/6882500/524368

(Verbatim quote):


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")
Community
  • 1
  • 1
datenwolf
  • 155,162
  • 12
  • 177
  • 284
1

The linker automatically assumes you want to use the console subsystem when you have a function named main. A few obvious (but untested) possibilities would be:

  1. Use an entry-point named WinMain
  2. Explicitly specify -subsystem:windows to the linker
  3. (1|2) use a completely different entry point, tell the linker both the entry point and the subsystem.
Jerry Coffin
  • 455,417
  • 76
  • 598
  • 1,067
  • Thanks, the WinMain option works. but When I setup the entry point to something else for example "Test" and rename the main() into Test() I got this error: Error **error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup** Can you please explain how to setup that? :) – codekiddy May 05 '12 at 04:33
  • You have to tell it the entry point you want to use with `-entry:Test`. I kind of put those in order though -- if using `WinMain` works, that's almost certainly the easiest, most dependable way to go. – Jerry Coffin May 05 '12 at 04:35
  • **Poject properties > linker > advanced > entry point > ...** What to type into that field? none of them work Test or -entry:Test, even when seting up in command line option :( for example **Poject properties > linker > advanced > command line > ...** -entry:Test – codekiddy May 05 '12 at 04:39
  • 2
    Here is info about how to keep your entry point named "main" and create window-type executable instead of console-type: http://stackoverflow.com/a/10156605/675078 – Mārtiņš Možeiko May 05 '12 at 04:49
  • Thank you alot for that link Martinš – codekiddy May 05 '12 at 04:56
  • sometimes the console output is not so bad - especially for the debug purpose, you can simply put printf messages and quickly see what is going on with your program. – fen May 05 '12 at 07:59