我如何告诉cmake不要创建控制台窗口? [英] How do I tell cmake not to create a console window?

查看:270
本文介绍了我如何告诉cmake不要创建控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过gcc实现此目的:

I can achieve this by gcc :

gcc -mwindows -o simple simple.c

但是只能在cmake中找到:

But only find this in cmake:

add_executable(simple WIN32 simple.c)

但它与<$ c并不完全相同$ c> -mwindows ,

这将要求入口点为 WinMain

,而 gcc -mwindows 不需要这个(可以是 main )。

while gcc -mwindows doesn't require this(can be main).

我应该如何正确执行?

推荐答案

如果使用:

add_executable(simple WIN32 simple.c)

然后必须提供WinMain函数。这就是add_executable的WIN32标志的含义:这意味着您要使其成为Windows程序,并提供WinMain函数。

then you must provide a WinMain function. That's what the WIN32 flag to add_executable means: it means you're going to make it a Windows program, and provide a WinMain function.

我建议这样做如果您确实在编写Windows应用程序。

I would recommend doing it this way if you're really writing a Windows application. It's what makes the most sense and fits most naturally with the underlying OS.

但是,如果您仍要传递gcc的 -mwindows标志,请使用主,然后只需将 -mwindows添加到CMAKE_CXX_FLAGS和/或CMAKE_C_FLAGS值。您可以在cmake-gui程序中通过交互式调整这些变量以使其包含 -mwindows来做到这一点,也可以使用CMake命令行来做到这一点,例如:

However, if you still want to pass gcc the "-mwindows" flag, but use a "main" anyway, then simply add "-mwindows" to the CMAKE_CXX_FLAGS and/or CMAKE_C_FLAGS value. You can do this in the cmake-gui program by adjusting those variables interactively to include "-mwindows" or you can do it with command line CMake, like this:

cmake -DCMAKE_C_FLAGS="-mwindows"

这篇关于我如何告诉cmake不要创建控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆