Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3847

Graphics programming • Re: help me set up Geany to work with the GTK+ library in C++

$
0
0
main.cpp

Code:

#include <gtk/gtk.h>// Callback function for button click eventstatic void on_button_clicked(GtkWidget *widget, gpointer data) {    gtk_button_set_label(GTK_BUTTON(widget), "Button Clicked!");}int main(int argc, char *argv[]) {    GtkWidget *window;    GtkWidget *button;    // Initialize GTK    gtk_init(&argc, &argv);    // Create a new window    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    gtk_window_set_title(GTK_WINDOW(window), "Simple Gtk+3 Window");    gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);    // Connect the window's destroy event to the main loop exit function    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);    // Create a new button    button = gtk_button_new_with_label("Click Me!");    // Connect the button's clicked event to the callback function    g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), NULL);    // Add the button to the window    gtk_container_add(GTK_CONTAINER(window), button);    // Show all widgets within the window    gtk_widget_show_all(window);    // Start the main loop    gtk_main();    return 0;}
CMakeLists.txt

Code:

# CMakeLists.txtcmake_minimum_required(VERSION 3.10)project(simple_window)set(CMAKE_CXX_STANDARD 20)set(CMAKE_CXX_STANDARD_REQUIRED True)# Find GTK3 packagefind_package(PkgConfig REQUIRED)pkg_check_modules(GTK3 REQUIRED gtk+-3.0)# Include GTK3 directoriesinclude_directories(${GTK3_INCLUDE_DIRS})# Add executableadd_executable(${PROJECT_NAME} main.cpp)# Link GTK3 librariestarget_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES})# Add compile definitionsadd_definitions(${GTK3_CFLAGS_OTHER})

Code:

sudo apt updatesudo apt install -y build-essential cmake pkg-config libgtk-3-dev
Now build it with cmake

Code:

mkdir buildcd buildcmake ..make
I have not used geany for building a project for a while, I mostly use it for working with yocto. So lets make sure you can actually build this first then we will work on config geany.
Build this to make sure you have everything installed.
Your cmake file sits next to main.cpp, in the directory you have main & cmake create the build directory

Statistics: Posted by foxsquirrel — Sun Aug 04, 2024 8:31 pm



Viewing all articles
Browse latest Browse all 3847

Trending Articles