4

I'm trying to compile the gtkmm Simple Example using Eclipse CDT, but it's not working for some reason

I'm compiling this on Mandriva Linux and GCC 4.4.3

I get this error, which I think is a linking error :

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

Sorry for the long error log, but I don't know how to make it shorter

Mahmoud Hanafy
  • 7,958
  • 12
  • 47
  • 62

2 Answers2

4

Project Property->C/C++ Build->Settings GCC C++ Compiler->Miscellaneous, add this string: pkg-config gtkmm-3.0 --cflags --libs into Other flags. GCC C++ Linker->Miscellaneous, add this string: pkg-config gtkmm-3.0 --cflags --libs in Linker flags. If you are using gtkmm 2.4, just replace "gtkmm-3.0" with "gtkmm-2.4"

Tick the GCC C++ COMPILER VERBOSE (_V) string.

Sun Junwen
  • 1,068
  • 10
  • 20
1

You have to add all the library's listed when you run pkg-config gtkmm-2.4 --cflags --libs in a terminal to Eclipse. As far as I have found, Eclipse doesn't play nice with pkg-config, so you have to add them manually.

Right click your Project > Properties > C/C++ Build > Settings

Under GCC C++ Compiler, in directories, add each directory listed when you run pkg-config gtkmm-2.4 --cflags (just the directories, drop the -I and -pthread)

Under GCC C++ Linker, in Libraries, add everything from pkg-config --libs (again, just add the libraries,drop the -l and -pthread)

Christian Smith
  • 605
  • 3
  • 11
  • How do I found out which directories get listed using pkg-config? – Mahmoud Hanafy Mar 21 '11 at 16:27
  • output of `pkg-config --cflags` on my computer is: – Christian Smith Mar 22 '11 at 11:39
  • output of `pkg-config --cflags` on my computer is: `-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 ...`(there are more) Take the -I(-'i' uppercase) off the front and add each individual directory with the add button. – Christian Smith Mar 22 '11 at 11:53
  • (If you can't tell, I'm new here, still trying to figure this site out, bear with me) – Christian Smith Mar 22 '11 at 11:54