我正在尝试使用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
对于长错误日志抱歉,但我不知道如何缩短
答案 0 :(得分:4)
项目属性 - > C / C ++构建 - >设置
GCC C ++编译器 - >杂项,将此字符串:pkg-config gtkmm-3.0 --cflags --libs
添加到其他标志中。
GCC C ++ Linker->杂项,在链接器标志中添加此字符串:pkg-config gtkmm-3.0 --cflags --libs
。
如果您使用的是gtkmm 2.4,只需将“gtkmm-3.0”替换为“gtkmm-2.4”
勾选GCC C ++ COMPILER VERBOSE(_V)字符串。
答案 1 :(得分:1)
在终端中运行pkg-config gtkmm-2.4 --cflags --libs
到Eclipse时,必须添加列出的所有库。据我所知,Eclipse与pkg-config不兼容,所以你必须手动添加它们。
右键单击您的项目>属性> C / C ++ Build>设置
在GCC C ++编译器下,在目录中添加运行时列出的每个目录
pkg-config gtkmm-2.4 --cflags
(只是目录,删除-I和-pthread)
在GCC C ++ Linker下,在Libraries中添加所有内容
pkg-config --libs
(再次,只需添加库,删除-l和-pthread)