Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Removing Console Window?  (Read 11143 times)

0 Members and 1 Guest are viewing this topic.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Removing Console Window?
« on: November 13, 2011, 02:43:54 am »
Excuse me, I'm somewhat new to programming, and I have a question about this paragraph in the Window - Opening a Window tutorial:
Quote
Under Windows operating systems, you may have created a "Windows Application" project, especially if don't want the console to show up. In such case, to avoid replacing main by WinMain, you can link with SFML_Main static library and keep a standard and portable main entry point.

These are my 2 questions:
  1. What is a static library, and do I link it like any other lib file?
  2. What functions should I include: SFML_Main, WinMain, main, or a combination?

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Removing Console Window?
« Reply #1 on: November 13, 2011, 01:06:19 pm »
Hi

1. A static library is where all the external libraries (such as SFML and Windows C run-time libraries) are compiled into the final executable produced by the compiler. This is the opposite to a "dynamic" situation where DLL files which contain the libraries are loaded automatically when your program run.

You'd use a static library when you cannot guarantee that any systems which your program may run on have the right version of the C run-time libraries installed. Most systems are kept reasonably up to date these days, but sometimes it's neccessary.

2.  For your main entry function, use this:

Code: [Select]

int _tmain()
{
// your code starts here...
}


You may need to include some Windows header files (Windows.h) so make sure you have the Windows SDK v7.1 (currently the latest) installed.

Hope that helps.
SFML 2.1

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Removing Console Window?
« Reply #2 on: November 14, 2011, 05:20:04 pm »
I forgot to say:

Quote

and do I link it like any other lib file?


Yes :-)
SFML 2.1

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Removing Console Window?
« Reply #3 on: November 14, 2011, 06:38:31 pm »
Ok, so I linked the SFML_Main library, and changed "int main" to "int _tmain", and now it gives me the error:
" undefined reference to `WinMain@16' "

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Removing Console Window?
« Reply #4 on: November 14, 2011, 06:56:08 pm »
Is _tmain() really needed? I don't think so, it's better to tell beginners about standard solutions and let them discover non-standard ones when they really need to.

Use main() :)
Laurent Gomila - SFML developer

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Removing Console Window?
« Reply #5 on: November 14, 2011, 07:01:11 pm »
But using main() initializes the console window?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Removing Console Window?
« Reply #6 on: November 14, 2011, 07:29:49 pm »
It's not the entry point that decides if the console will show up or not. It's the the other way round: if you choose a console project your entry point will be main, if you choose a Win32 application your entry point will be WinMain -- but then with sfml-main you can use a regular main() and keep your code portable across OSes.
Laurent Gomila - SFML developer

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Removing Console Window?
« Reply #7 on: November 14, 2011, 08:55:17 pm »
When I started my project, I just set it as an Empty Project.  What should I do about that?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Removing Console Window?
« Reply #8 on: November 14, 2011, 09:15:06 pm »
Change the "subsystem" option (in the linker settings) in your project properties, from "console" to "Windows".
Laurent Gomila - SFML developer