Search code examples
c++11compilationstdstringgtkmmgcc5

gtkmm undefined reference to certain gtk::builder function add_from_file


I am using eclipse, mingw-w64, gtkmm2.4, glade to compile some simple program.

I can compile hello world gtkmm examples, following a tutorial to, however when it comes to glade came a little strange undefined to error.

program that compiled and run smoothly, which was the gtkmm 2.24 simple example tutorial https://developer.gnome.org/gtkmm-tutorial/2.24/sec-basics-simple-example.html.en

#include <gtkmm.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    Gtk::Main::run(*window);
    return 0;
}

however when I try to run another simple example from the glade chapter (24.2.1) things does not work out.

https://developer.gnome.org/gtkmm-tutorial/2.24/sec-builder-accessing-widgets.html.en example:

#include <gtkmm.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);
    //Gtk::Window window; //I changed it to fit with the glade example

    Gtk::Window* window;  //I changed this line from the example

    //////////////// this part was pretty much just copied out from the example//////
    Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create();
    try
      {
        refBuilder->add_from_file("something.glade"); //this is the line with problem.
      }
      catch(const Glib::FileError& ex)
      {
        std::cerr << "FileError: " << ex.what() << std::endl;
        return 1;
      }
      catch(const Gtk::BuilderError& ex)
      {
        std::cerr << "BuilderError: " << ex.what() << std::endl;
        return 1;
      }
    refBuilder->get_widget("window1", window);
    //////////////// end of copied out from the example//////

    Gtk::Main::run(*window);
    return 0;
}

when compiled, it gave error as follow test.cpp:(.text.startup+0x281): undefined reference to Gtk::Builder::add_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

It seems to take the argument "something.glade" as type std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& (which I have no idea what it is).

according to the gtkmm manual (https:developer.gnome.org/gtkmm/stable/classGtk_1_1Builder.html#aa3f4af4e7eaf7861c8283dc0dbd5254c) seems it only takes Gtk::Builder::add_from_file(const std::string & filename). So is the argument type really the problem?

I have tried casting it as std::string by doing std::string() or string(), but it gave the same error.

I have tried commenting out the line in question, and it compiled fine.

  • Gtk::Builder::create() did not receive undefined reference to compilation error
  • refBuilder->get_widget("window1", window); did not receive undefined reference to compilation error

So now I am scratching my head all over this seems trivial issue. Please provide some help.

For more information

  • pkg-config --cflags --libs yielded -IE:/gtkmm64/include/gtkmm-2.4 -IE:/gtkmm64/lib/gtkmm-2.4/include -IE:/gtkmm64/include/atkmm-1.6 -IE:/gtkmm64/include/giomm-2.4 -IE:/gtkmm64/lib/giomm-2.4/include -IE:/gtkmm64/include/pangomm-1.4 -IE:/gtkmm64/lib/pangomm-1.4/include -IE:/gtkmm64/include/gtk-2.0 -IE:/gtkmm64/include/gdkmm-2.4 -IE:/gtkmm64/lib/gdkmm-2.4/include -IE:/gtkmm64/include/atk-1.0 -IE:/gtkmm64/include/glibmm-2.4 -IE:/gtkmm64/lib/glibmm-2.4/include -IE:/gtkmm64/include/glib-2.0 -IE:/gtkmm64/lib/glib-2.0/include -IE:/gtkmm64/include/sigc++-2.0 -IE:/gtkmm64/lib/sigc++-2.0/include -IE:/gtkmm64/include/cairomm-1.0 -IE:/gtkmm64/lib/cairomm-1.0/include -IE:/gtkmm64/include/pango-1.0 -IE:/gtkmm64/include/cairo -IE:/gtkmm64/include -IE:/gtkmm64/include/freetype2 -IE:/gtkmm64/include/libpng14 -IE:/gtkmm64/lib/gtk-2.0/include -IE:/gtkmm64/include/gdk-pixbuf-2.0 -LE:/gtkmm64/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpng14 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl, Which I have included into the project
  • pkg-config --modversion gtkmm2.4 yielded 2.22.0, so I doubt it has anything to do with the 2.14 requirement for add_from_file()
  • pkg-config --modversion gtk+2.0 yielded 2.22.0
  • I did not use any flags like --std=c++xx.
  • windows 8 64bit

Solution

  • seems Converting std::__cxx11::string to std::string solved it.

    put #define _GLIBCXX_USE_CXX11_ABI 0 at start because I am using gcc 5.