将 gtkmm 与 Eclipse CDT 一起使用

Posted

技术标签:

【中文标题】将 gtkmm 与 Eclipse CDT 一起使用【英文标题】:Using gtkmm with Eclipse CDT 【发布时间】:2011-02-10 13:01:22 【问题描述】:

我正在尝试使用 Eclipse CDT 编译 gtkmm Simple Example,但由于某种原因它无法正常工作

我正在 Mandriva Linux 和 GCC 4.4.3 上编译它

我收到此错误,我认为这是一个链接错误:

Building target: Test
Invoking: GCC C++ Linker
g++ -L/usr/include/gtkmm-2.4 -o"Test"  ./test.o   
./test.o: In function `main':
test.cpp:(.text+0x39): undefined reference to `Gtk::Main::Main(int&, char**&, bool)'
test.cpp:(.text+0x43): undefined reference to `Gtk::Window::Window(Gtk::WindowType)'
test.cpp:(.text+0x4b): undefined reference to `Gtk::Main::run(Gtk::Window&)'
test.cpp:(.text+0x53): undefined reference to `Gtk::Window::~Window()'
test.cpp:(.text+0x5b): undefined reference to `Gtk::Main::~Main()'
test.cpp:(.text+0x82): undefined reference to `Gtk::Main::~Main()'
test.cpp:(.text+0x95): undefined reference to `Gtk::Window::~Window()'
./test.o: In function `global constructors keyed to main':
test.cpp:(.text+0xaf): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0xbe): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0xd2): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0xe1): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0xf5): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0x104): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0x118): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0x127): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0x13b): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0x14a): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0x15e): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0x16d): undefined reference to `Glib::ustring::~ustring()'
test.cpp:(.text+0x181): undefined reference to `Glib::ustring::ustring(char const*)'
test.cpp:(.text+0x190): undefined reference to `Glib::ustring::~ustring()'
collect2: ld returned 1 exit status
make: *** [Test] Error 1

抱歉,错误日志太长了,但我不知道如何缩短它

【问题讨论】:

这里所说的你做到了吗:library.gnome.org/devel/gtkmm-tutorial/unstable/… 我已经安装了devel包,还是你的意思是我应该从源代码编译它? 【参考方案1】:

项目属性->C/C++ Build->设置 GCC C++ Compiler->Miscellaneous,将此字符串:pkg-config gtkmm-3.0 --cflags --libs 添加到其他标志中。 GCC C++ Linker->Miscellaneous,在链接器标志中添加这个字符串:pkg-config gtkmm-3.0 --cflags --libs。 如果您使用的是 gtkmm 2.4,只需将“gtkmm-3.0”替换为“gtkmm-2.4”

勾选 GCC C++ COMPILER VERBOSE (_V) 字符串。

【讨论】:

哦!这比我的好!更容易添加。【参考方案2】:

您必须将在终端中运行pkg-config gtkmm-2.4 --cflags --libs 时列出的所有库添加到Eclipse。据我发现,Eclipse 与 pkg-config 配合得并不好,因此您必须手动添加它们。

右键单击您的项目 > 属性 > C/C++ 构建 > 设置

在 GCC C++ 编译器下,在目录中,添加运行时列出的每个目录 pkg-config gtkmm-2.4 --cflags (只是目录,删除 -I 和 -pthread)

在 GCC C++ Linker 下的 Libraries 中,添加来自 pkg-config --libs (同样,只需添加库,删除 -l 和 -pthread)

【讨论】:

我如何找出使用 pkg-config 列出的目录? pkg-config --cflags 在我的电脑上的输出是: pkg-config --cflags 在我的计算机上的输出是:-pthread -I/usr/include/gtkmm-2.4 -I/usr/lib/gtkmm-2.4/include -I/usr/include/giomm-2.4 -I/usr/lib/giomm-2.4/include -I/usr/include/pangomm-1.4 -I/usr/lib/pangomm-1.4/include -I/usr/include/gtk-2.0 -I/usr/include/gtk-unix-print-2.0 -I/usr/include/atkmm-1.6 -I/usr/include/gdkmm-2.4 -I/usr/lib/gdkmm-2.4/include -I/usr/include/glibmm-2.4 -I/usr/lib/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include ...(还有更多)去掉前面的 -I(-'i' 大写字母),然后使用添加按钮添加每个单独的目录。 (如果你看不出来,我是新来的,还在想这个网站,请多多包涵)

以上是关于将 gtkmm 与 Eclipse CDT 一起使用的主要内容,如果未能解决你的问题,请参考以下文章

Eclipse CDT:没有规则使目标全部

gtkmm:将容器小部件(Box)中的元素堆叠在一起

在 Eclipse 中为 C++ 设置 GTKmm

eclipse能不能开发C/C++?

OpenCV 和 Eclipse CDT

是否可以将 GTK+ 与 C++ 一起使用?