0
#include <gtk/gtk.h>

G_MODULE_EXPORT void on_login_window_destroy()
{
    gtk_main_quit();
}

int main (int argc, char **argv)
{
    gtk_init(&argc, &argv);

    GtkBuilder *builder;
    GtkWidget *window;

    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "../layout.glade", NULL);

    window = GTK_WIDGET(gtk_builder_get_object(builder, "login_window"));
    gtk_builder_connect_signals(builder, NULL);

    g_object_unref(builder);

    gtk_widget_show(window);

    gtk_main();
    return 0;
}

this is my main.cpp

and

cmake_minimum_required(VERSION 3.6)
project(Chat)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -rdynamic")

set(SOURCE_FILES main.cpp)
add_executable(Chat ${SOURCE_FILES})

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})

add_definitions(${GTK3_CFLAGS_OTHER})

target_link_libraries(Chat ${GTK3_LIBRARIES})

is my CMakeLists.txt Glade template works and window shows but the signal is not working. I got below error:

(Chat:19486): Gtk-WARNING **: 11:44:05.546: Could not find signal handler 'on_login_window_destroy'.  Did you compile with -rdynamic?

I used -rdynamic flag but still got the same error.

But below code works in terminal. I would need to either make CMake to run below code sothat it works or what do you think.?

gcc -o Chat main.cpp -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic

I am using UBUNTU 18.04 with all the libraries (I think so.)

Suson Waiba
  • 156
  • 1
  • 2
  • 9
  • Try building it using CMake from terminal and see, what commands are called. https://stackoverflow.com/questions/2670121/using-cmake-with-gnu-make-how-can-i-see-the-exact-commands – Alexander Dmitriev May 04 '18 at 08:31
  • From what you suggested. it uses `/usr/bin/c++ -std=c++11 CMakeFiles/Chat.dir/main.cpp.o -o Chat -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 ` – Suson Waiba May 06 '18 at 02:02
  • so, ?? I dont know about cmake and adding flags at required position...? – Suson Waiba May 06 '18 at 02:03

2 Answers2

1

For what it's worth, I had the exact same issue (and error messages), although with gtk-2.0. What solved it on macOS was to use use the FindGTK2 module directly, instead of the pkg-config command. For instance:

find_package(GTK2 REQUIRED gtk glade)
if(GTK2_FOUND)
    include_directories(${GTK2_INCLUDE_DIRS})
    link_libraries(${GTK2_LIBRARIES})
    add_definitions(${GTK2_DEFINITIONS})
endif()

On Linux, I also had to add set(CMAKE_EXE_LINKER_FLAGS "-rdynamic")

Adriweb
  • 227
  • 3
  • 17
0

I guess after going through alot of search.. I found that it only works with c and I have tested that; found to be true. so I am using gtkmm.h which seems to be working as expected.

Suson Waiba
  • 156
  • 1
  • 2
  • 9