8

I use Eclipse and I wanted to use gtkmm in it. I have following code:

#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;
}

I added pkg-config --cflags --libs gtkmm-3.0 (with grave accents, of course) to Cross G++ Compiler Miscellanous options into Other flags and the same to the Cross G++ Compiler Miscellanous options into Linker flags. And it doesn't work!

Here's the compile log:

**** 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 ****

And I don't know why... When I compile it in terminal by: g++ -O0 -g3 -Wall -c -fmessage-length=0 'pkg-config --cflags --libs gtkmm-3.0' -o ./test ./main.cpp it works...

m4tx
  • 4,139
  • 5
  • 37
  • 61

2 Answers2

13

I found a solution: In Linker options, in Command line pattern I moved ${FLAGS} to the end, e.g.:

Before: ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

After: ${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}

And now it works.

m4tx
  • 4,139
  • 5
  • 37
  • 61
  • Wow, thanks! How did you discover this was the solution? – Dai Sep 28 '16 at 06:10
  • [This article by Eli Bendersky about Linkers and Loaders](https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking) provides a good explanation with examples. – Pau Coma Ramirez Dec 18 '20 at 22:39
1

You must divide to pkg-config --cflags <etc> an add there where it's now (compiler options) and then add pkg-config --libs <etc> to linker options

Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • U must do something wrong cause it MUST run. I've done it a lot of times and it's always works. – Hauleth Dec 14 '11 at 14:26
  • 2
    Ok, thanks for help. I found a solution: I edited Linker Command Line pattern - I moved ${FLAGS} to the end. – m4tx Dec 14 '11 at 15:11