Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass no argument into pragma comment in c++

I want my program to show the console window if it detects the solution configuration is debug. If it detects release, then the console window should not show up

#include "Window.h"

int main(int argc, char* argv[]) {
    Window Game;

#if defined(_DEBUG)
#pragma comment(linker, "/SUBSYSTEM:console /ENTRY:")
    Game.run();
#else
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
    Game.run();
#endif
}

The source code above doesn’t work because:

LNK1146 no argument specified with option '/ENTRY:'

So I want to know how to pass no argument in #pragma comment (or just improve this source code in general)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(using Visual Studio 2023 and C++ 20)

Any help is appreciated!

>Solution :

The /ENTRY flag for MSVC always has to be followed by :function_name. So if you want to keep the default, just don’t pass /ENTRY at all for that case:

#include "Window.h"

int main(int argc, char* argv[]) {
    Window Game;

#if defined(_DEBUG)
#pragma comment(linker, "/SUBSYSTEM:console")
    Game.run();
#else
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
    Game.run();
#endif
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading