Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

c - What's the equivalent of gcc's -mwindows option in cmake?

I'm following the tuto:

http://zetcode.com/tutorials/gtktutorial/firstprograms/

It works but each time I double click on the executable,there is a console which I don't want it there.

How do I get rid of that console?

I tried this:

add_executable(Cmd WIN32 cmd.c)

But got this fatal error:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
Cmd.exe : fatal error LNK1120: 1 unresolved externals

While using gcc directly works:

gcc -o Cmd cmd.c -mwindows ..

I'm guessing it has something to do with the entry function: int main( int argc, char *argv[]),but why gcc works?

How can I make it work with cmake?

UPDATE

Let me paste the source code here for convenience:

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);

  gtk_main();

  return 0;
}

UPDATE2

Why gcc -mwindows works but add_executable(Cmd WIN32 cmd.c) not?

Maybe that's not the equivalent for -mwindows in cmake?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

add_executable(Cmd WIN32 cmd.c)

Tells CMake this is a Windows program, and it looks for WinMain instead of main. If you want to see the flags being used you can run make VERBOSE=1. The question might be how do you define WinMain for gtk apps? I know with Qt, you link in a library that defines it for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...