我使用Eclipse並且我想在其中使用gtkmm。我有以下代碼:Eclipse和Gtkmm - 「未定義的引用」
#include <gtkmm.h>
#include <iostream>
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::Window mainWindow;
Gtk::Button button("Click here");
mainWindow.set_title("Eclipse/GTKmm Demo");
mainWindow.set_border_width(4);
mainWindow.set_default_size(200, 50);
mainWindow.add(button);
button.show();
Gtk::Main::run(mainWindow);
return 0;
}
我加入pkg-config --cflags --libs gtkmm-3.0
(具有重音符,當然)到跨G ++編譯器計算其它選擇成其他標誌和相同的交叉G ++編譯器計算其它選項加入到鏈接器標誌。它不起作用!
這裏是編譯日誌:
**** Build of configuration Debug for project User Directory Changer ****
make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 `pkg-config --cflags --libs gtkmm-3.0` -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: User Directory Changer
Invoking: Cross G++ Linker
g++ `pkg-config --cflags --libs gtkmm-3.0` -o "User Directory Changer" ./main.o
./main.o: In function `main':
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:12: undefined reference to `Gtk::Main::Main(int&, char**&, bool)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:14: undefined reference to `Gtk::Window::Window(Gtk::WindowType)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Glib::ustring::ustring(char const*)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Gtk::Button::Button(Glib::ustring const&, bool)'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:16: undefined reference to `Glib::ustring::~ustring()'
/home/m4tx1/Dropbox/Projects/User Directory Changer/Debug/../main.cpp:18: undefined reference to `Glib::ustring::ustring(char const*)'
[etc...]
collect2: ld returned 1 exit status
make: *** [User Directory Changer] Error 1
**** Build Finished ****
而且我不知道爲什麼...當我用終端編譯:g++ -O0 -g3 -Wall -c -fmessage-length=0 'pkg-config --cflags --libs gtkmm-3.0' -o ./test ./main.cpp
它的工作原理...
是的,我試過了,但是...它不工作太:( – m4tx 2011-12-14 04:59:47
你必須做錯誤的事情,因爲它必須運行,我已經做了很多次,它總是有效的 – Hauleth 2011-12-14 14:26:04