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.

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

For more information


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.