如何在Linux Mint中为Windows编译C GTK3 +程序? [英] How to compiling C GTK3+ program in Linux mint for windows?
问题描述
我正在使用Linux Mint,gcc-7和mingw-w64.我想在Linux中使用mingw编译ac gtk3 +程序,以便它将生成可以在Windows中运行的.exe文件.我能够编译正常的c使用mingw的程序,但是我不能编译gtk程序.我可以用gcc编译gtk程序,但不能用mingw编译.
I am using Linux mint and gcc-7 and mingw-w64.I want to compile a c gtk3+ program in Linux using mingw so that it will produce .exe file which can be run in windows.I am able to Compile normal c programs using mingw,But I can't compile gtk programs.I can compile gtk programs with gcc but not with mingw.
I had installed mingw as told here :- How to compile executable for Windows with GCC with Linux Subsystem?
现在,我想编译从等等.......(我要粘贴最后一行,因为此输出会更大)
and so .......( I am pasting the last line as this output is way more big)
collect2: error: ld returned 1 exit status
我已经阅读了本教程:- http://www.tarnyko. net/en/?q = node/45
I already went via this tutorial :-http://www.tarnyko.net/en/?q=node/45
现在相对于此 tutorail,但这一次我下载了gtk+-bundle_3.6.4-20131201_win64.zip
现在我得到以下输出:-
Now vis this tutorail again but this time I had downloaded gtk+-bundle_3.6.4-20131201_win64.zip
and now I am getting this output:-
smit@smit-Aspire-5742:~/programs/c programs/test$ x86_64-w64-mingw32-gcc test.c `pkg-config --cflags gtk+-3.0 --libs`
In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9:0,
from /usr/include/glib-2.0/glib/gtypes.h:32,
from /usr/include/glib-2.0/glib/galloca.h:32,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
from /usr/include/gtk-3.0/gdk/gdk.h:30,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from test.c:1:
/usr/include/glib-2.0/glib/gtypes.h: In function ‘_GLIB_CHECKED_ADD_U64’:
/usr/include/glib-2.0/glib/gmacros.h:232:53: error: size of array ‘_GStaticAssertCompileTimeAssertion_0’ is negative
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
^
/usr/include/glib-2.0/glib/gmacros.h:229:47: note: in definition of macro ‘G_PASTE_ARGS’
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
^
/usr/include/glib-2.0/glib/gmacros.h:232:44: note: in expansion of macro ‘G_PASTE’
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
^
/usr/include/glib-2.0/glib/gtypes.h:422:3: note: in expansion of macro ‘G_STATIC_ASSERT’
G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
^
In file included from /usr/include/glib-2.0/gio/gio.h:46:0,
from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from test.c:1:
/usr/include/glib-2.0/gio/gcredentials.h: At top level:
/usr/include/glib-2.0/gio/gcredentials.h:75:1: error: unknown type name ‘uid_t’
uid_t g_credentials_get_unix_user (GCredentials *credentials,
^
/usr/include/glib-2.0/gio/gcredentials.h:79:52: error: unknown type name ‘uid_t’
uid_t uid,
^
推荐答案
I've gone via this tutorial 5 or maybe more times and I found what was wrong.I was exacting commands from wrong directories and downloading wrong version of GTK+ 3 Windows binaries
.
我的mingw版本是mingw64,因此我需要下载win64
版本.
My version of mingw is mingw64 thus I needed to download win64
version.
并且我正在/opt/gtk3-win64中执行命令export PKG_CONFIG_PATH=/opt/gtk3-win64/lib/pkgconfig
,但是我需要通过test.c文件所在的目录来执行此命令.
and I was executing command export PKG_CONFIG_PATH=/opt/gtk3-win64/lib/pkgconfig
from /opt/gtk3-win64,but I needed to execute this command via directory in which my test.c file was.
我将为以后的读者简化本教程.
I'll make this tutorial easy for future readers.
-
通过命令安装
mingw cross-compiler
sudo apt-get install mingw-w64
然后从此处下载GTK+ 3 Windows binaries
(此教程较旧,这是最新链接):- http://win32builder.gnome.org/
下载我错误的版本时,请下载适当的版本.不要犯与我相同的错误.
Then Download GTK+ 3 Windows binaries
from here(Link in this tutorial is old,here is latest link):- http://win32builder.gnome.org/
Download appropriate version as I was downloading wrong version.don't make the same mistake as mine.
通过命令
sudo mkdir /opt/gtkwin && sudo unzip <name of the zip file> -d /opt/gtkwin
然后转到您已解压缩zip文件的目录.在这种情况下,我已像cd /opt/gtkwin
一样在/opt/gtkwin/中解压缩并执行以下命令
then Go to directory in which you have extracted the zip file.In this case I have extracted in /opt/gtkwin/ like cd /opt/gtkwin
and execute the following command
find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$PWD@" -i "$pc"; done
现在转到您要编译的.c文件所在的目录,然后执行此命令
Now go to you directory in which you have .c file which you which to compile.and execute this command
export PKG_CONFIG_PATH=/opt/gtkwin/lib/pkgconfig
现在通过
now compile the program by
x86_64-w64-mingw32-gcc test.c `pkg-config --cflags gtk+-3.0 --libs`
(用于64位)
和32位
i586-mingw32msvc-gcc test.c `pkg-config --cflags --libs gtk+-3.0`
另外,您应该访问该教程,因为我从那里学到了它:- http ://www.tarnyko.net/en/?q = node/45
Also you should visit this tutorial as I had learn this from there :- http://www.tarnyko.net/en/?q=node/45
这将创建不能在UNIX中运行的.exe
文件,因为该文件旨在在DOS上运行
this will create .exe
file which can't run in UNIX as it is targeted to run on DOS
这篇关于如何在Linux Mint中为Windows编译C GTK3 +程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!