5

I'm fairly new to Gtk programming. I'm using the Gtkmm library to write a simple GUI for my application.

The GUI is part of a larger application, which actually compiles to two separate executables, however I don't believe this is relevant since this question only concerns one of the two executables.

Anyway, I have the following code in client.cpp:

#include "client.hpp"

int main() {
    auto builder = Gtk::Builder::create();
}

And in client.hpp I'm simply including iostream, glibmm.h, and various gtkmm widget headers, as well as gtkmm/builder.h.

My makefile is a mess, but here it is:

CXXFLAGS= -std=c++14 -g
LDFLAGS=-lgmp -pthread $(shell pkg-config -libs gtkmm-3.0)
SERVER_EXE=server
CLIENT_EXE=client
CXX=g++
DIST_DIR=.
BUILD_DIR=./build

SERVER_CXXFLAGS=
CLIENT_CXXFLAGS=$(shell pkg-config --cflags gtkmm-3.0)

INCLUDE_DIRS=./include
INCLUDE_PARAMS=$(foreach d, $(INCLUDE_DIRS), -I$d)

SERVER_OBJECTS=rsa.o server_entry.o server.o
SERVER_OBJECT_PATHS=$(foreach o, $(SERVER_OBJECTS), $(BUILD_DIR)/$o)

CLIENT_OBJECTS=resources.o client.o
CLIENT_OBJECT_PATHS=$(foreach o, $(CLIENT_OBJECTS), $(BUILD_DIR)/$o)

all: $(SERVER_OBJECT_PATHS) $(CLIENT_OBJECT_PATHS)
    mkdir -p $(DIST_DIR)
    $(CXX) $(CLIENT_OBJECT_PATHS) -o $(DIST_DIR)/$(CLIENT_EXE) $(LDFLAGS)
    $(CXX) $(SERVER_OBJECT_PATHS) -o $(DIST_DIR)/$(SERVER_EXE) $(LDFLAGS)

clean:
    rm -rf $(BUILD_DIR)
    rm $(DIST_DIR)/$(CLIENT_EXE) $(DIST_DIR)/$(SERVER_EXE)

$(BUILD_DIR)/%.o: %.cpp
    mkdir -p $(BUILD_DIR)
    $(CXX) -c $< $(INCLUDE_PARAMS) -o $@ $(CXXFLAGS) $(SERVER_CXXFLAGS) $(CLIENT_CXXFLAGS)

resources.cpp:
    glib-compile-resources --target=resources.cpp --generate-source windows.gresource.xml

I realise that's a lot to take in, since it's actually building two executables, but for this question you can safely only regard things which are related to the client program.

The rule right at the bottom is used to turn the glade file I made into a c++ file which can be linked to my client.cpp file.

Anyway, when I run my program I get the following output:

(process:16593): GLib-GObject-CRITICAL **: 23:15:27.886: g_object_set_qdata_full: assertion 'quark > 0' failed

I'm at a complete loss as to what this error message could mean. Since I'm not very experienced with this library, I'm not sure quite what to make of it. I also tried adding a line after my code to load the builder widgets from a resource, but that created even more critical errors and segfaulted. I'm hoping if I can fix this first error, everything else will fall into place. Any thoughts? Thanks!

UPDATE 1: When I change the source of client.cpp to the source code supplied here, it works perfectly! So that's odd..

Jacob Garby
  • 773
  • 7
  • 22
  • Run your program under `gdb` with `G_DEBUG=fatal-warnings` set in the environment and look at the backtrace (or post it here). See https://developer.gnome.org/glib/stable/glib-running.html#G-DEBUG:CAPS – Philip Withnall Dec 25 '18 at 00:46
  • @PhilipWithnall thank you for the response. Am I right in thinking that to do this I type `G_DEBUG=fatal-warnings` and then `gdb client`, then when gdb is running I type 'run' and then 'where'? Because when I do that it just says No stack. – Jacob Garby Dec 25 '18 at 17:39
  • Yes, type them all in one command (`G_DEBUG=fatal-warnings gdb ./client`) or use `export G_DEBUG=fatal-warnings` first, then `gdb ./client`). You’ll need debug symbols installed for GLib, and your application to be compiled with `-g -O1`, in order to get a backtrace. – Philip Withnall Dec 26 '18 at 10:59

1 Answers1

8

I'm pretty sure GLibMM must be initialized with Glib::init() before you call any Glib/Gtk functions. Gtk::Application::create() will do that for you, that's why the example just works.

Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54