为什么我无法编译GTK+使用MinGW?
帮助我 Stackoverflow!
所以,我觉得我已经正确设置了我的环境,但我无法构建我的程序!
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
using namespace std;
/*
* simple gtk application
* author jan bodnar
* date february 17, 2008
*/
int main(int argc, char** argv) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
gtk_window_set_title(GTK_WINDOW(window), "gtkapp");
gtk_widget_show(window);
g_signal_connect(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_main();
return (EXIT_SUCCESS);
}
我从这个命令生成了包含目录列表: pkg-config --cflags gtk+-2.0
然后我在 netbeans 的 C++ 编译器设置中添加了包含文件...
我的包含目录:
../gtk/include/gtk-2.0 ../gtk/lib/gtk-2.0/include ../gtk/include/atk-1.0 ../gtk/include/cairo ../gtk/include/pango-1.0 ../gtk/include/glib-2.0 ../gtk/lib/glib-2.0/include ../gtk/include/libpng12
然后我从这个命令生成了一个库列表: pkg-config --libs gtk+-2.0
然后将我的库添加到 netbeans 中的链接器命令行中:
-LC:/tools/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo - lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl
但我仍然无法编译一个简单的程序!我一定错过了一些愚蠢的事情,但我一生都无法弄清楚。
错误:
build/Debug/MinGW-Windows/main.o: In function `main': C:\Projects\glade_netbeans3\gtk_tut/main.cpp:24: undefined reference to `gtk_init_abi_check' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:26: undefined reference to `gtk_window_new' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `gtk_window_set_position' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `gtk_window_set_default_size' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `gtk_window_set_title' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:30: undefined reference to `gtk_widget_show' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:33: undefined reference to `gtk_main_quit' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:33: undefined reference to `g_signal_connect_data' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:35: undefined reference to `gtk_mainmake[2]: Leaving directory `/c/Projects/glade_netbeans3/gtk_tut' ' collect2: ld returned 1 exit status make[2]: *** [dist/Debug/MinGW-Windows/gtk_tut.exe] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 make[1]: Leaving directory `/c/Projects/glade_netbeans3/gtk_tut' BUILD FAILED (exit value 2, total time: 1s)
Netbeans 生成的 Make 文件:
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre:
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk
Help me Stackoverflow!
So, I feel that I have set up my environment correctly but I cannot build my program!
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
using namespace std;
/*
* simple gtk application
* author jan bodnar
* date february 17, 2008
*/
int main(int argc, char** argv) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
gtk_window_set_title(GTK_WINDOW(window), "gtkapp");
gtk_widget_show(window);
g_signal_connect(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_main();
return (EXIT_SUCCESS);
}
I generated my list of include dirs from this command: pkg-config --cflags gtk+-2.0
Then I added the include files in the C++ compiler settings in netbeans...
My include directories:
../gtk/include/gtk-2.0 ../gtk/lib/gtk-2.0/include ../gtk/include/atk-1.0 ../gtk/include/cairo ../gtk/include/pango-1.0 ../gtk/include/glib-2.0 ../gtk/lib/glib-2.0/include ../gtk/include/libpng12
Then I generated a list of libs from this command: pkg-config --libs gtk+-2.0
Then added my libs to the linker command line in netbeans with this:
-LC:/tools/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl
But still I cannot compile a simple program! I must be missing something stupid, but I cannot for the life of me figure it out.
errors:
build/Debug/MinGW-Windows/main.o: In function `main': C:\Projects\glade_netbeans3\gtk_tut/main.cpp:24: undefined reference to `gtk_init_abi_check' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:26: undefined reference to `gtk_window_new' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:27: undefined reference to `gtk_window_set_position' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:28: undefined reference to `gtk_window_set_default_size' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `gtk_window_get_type' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `g_type_check_instance_cast' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:29: undefined reference to `gtk_window_set_title' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:30: undefined reference to `gtk_widget_show' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:33: undefined reference to `gtk_main_quit' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:33: undefined reference to `g_signal_connect_data' C:\Projects\glade_netbeans3\gtk_tut/main.cpp:35: undefined reference to `gtk_mainmake[2]: Leaving directory `/c/Projects/glade_netbeans3/gtk_tut' ' collect2: ld returned 1 exit status make[2]: *** [dist/Debug/MinGW-Windows/gtk_tut.exe] Error 1 make[1]: *** [.build-conf] Error 2 make: *** [.build-impl] Error 2 make[1]: Leaving directory `/c/Projects/glade_netbeans3/gtk_tut' BUILD FAILED (exit value 2, total time: 1s)
Make file generated by Netbeans:
#
# There exist several targets which are by default empty and which can be
# used for execution of your targets. These targets are usually executed
# before and after some main targets. They are:
#
# .build-pre: called before 'build' target
# .build-post: called after 'build' target
# .clean-pre: called before 'clean' target
# .clean-post: called after 'clean' target
# .clobber-pre: called before 'clobber' target
# .clobber-post: called after 'clobber' target
# .all-pre: called before 'all' target
# .all-post: called after 'all' target
# .help-pre: called before 'help' target
# .help-post: called after 'help' target
#
# Targets beginning with '.' are not intended to be called on their own.
#
# Main targets can be executed directly, and they are:
#
# build build a specific configuration
# clean remove built files from a configuration
# clobber remove all built files
# all build all configurations
# help print help mesage
#
# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
# .help-impl are implemented in nbproject/makefile-impl.mk.
#
# Available make variables:
#
# CND_BASEDIR base directory for relative paths
# CND_DISTDIR default top distribution directory (build artifacts)
# CND_BUILDDIR default top build directory (object files, ...)
# CONF name of current configuration
# CND_PLATFORM_${CONF} platform name (current configuration)
# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
#
# NOCDDL
# Environment
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
# build
build: .build-post
.build-pre:
# Add your pre 'build' code here...
.build-post: .build-impl
# Add your post 'build' code here...
# clean
clean: .clean-post
.clean-pre:
# Add your pre 'clean' code here...
.clean-post: .clean-impl
# Add your post 'clean' code here...
# clobber
clobber: .clobber-post
.clobber-pre:
# Add your pre 'clobber' code here...
.clobber-post: .clobber-impl
# Add your post 'clobber' code here...
# all
all: .all-post
.all-pre:
# Add your pre 'all' code here...
.all-post: .all-impl
# Add your post 'all' code here...
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre:
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
# help
help: .help-post
.help-pre:
# Add your pre 'help' code here...
.help-post: .help-impl
# Add your post 'help' code here...
# include project implementation makefile
include nbproject/Makefile-impl.mk
# include project make variables
include nbproject/Makefile-variables.mk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的程序可以编译,但无法链接。问题是,由于您必须包含所有目录才能包含所有标头,因此还必须指定库的目录。总结一下:问题是 netbeans 无法找到要链接的库。
在您的项目中,转到“属性”、“链接”,然后在“其他库目录”中,您必须提及包含 Gtkmm 发行版中的库的所有目录。
希望这有帮助。
Your program compiles, but it does not link. The problem is that, as you have to include all directories for including all headers, you must also indicate the directories for the libraries as well. To summarize: the problem is that netbeans is unable to find the libraries to link.
In your project, go to Properties, Link, and in "Additional Library directories", you will have to mention all directories that include libraries in the Gtkmm distribution.
Hope this helps.