Search code examples
user-interfaceinstallationpasswordsgtkgtk3

How to use GcrSecureEntryBuffer in a GTK3 application?


I want to use a GcrSecureEntryBuffer for a GtkEntry, because the user will enter passwords in it. I found the following links.

I wrote this this toy program ztest.c:

#include <gck/gck.h>
#include <gcr/gcr.h>
#include <gtk/gtk.h>

int main(void)
{
    gtk_init(0, NULL);

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    GtkWidget *entry = gtk_entry_new_with_buffer(gcr_secure_entry_buffer_new());
    gtk_container_add(GTK_CONTAINER(window), entry);

    gtk_widget_show_all(window);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_main();
}

and installed the required libraries.

sudo apt install libgtk-3-dev libgcr-3-dev gcr p11-kit p11-kit-modules

Based on what I learnt from the GCR and GCK headers, I compiled this code with

gcc -DGCR_API_SUBJECT_TO_CHANGE -DGCK_API_SUBJECT_TO_CHANGE $(pkg-config --cflags gtk+-3.0) -I/usr/include/gcr-3 -I/usr/include/gck-1/ -I/usr/include/p11-kit-1/ -o test ztest.c $(pkg-config --libs gtk+-3.0)

and got the following error. (There were no other warnings about undefined functions.)

/usr/bin/ld: /tmp/ccxVu7EL.o: in function `main':
ztest.c:(.text+0x26): undefined reference to `gcr_secure_entry_buffer_new'
collect2: error: ld returned 1 exit status

How do I fix this? Is there anything else that must be installed? And is there a pkg-config command for compiler and linker flags for these libraries?


Solution

  • When you talk about "Gcr", you actually talk about 2 different libraries (each with their own pkg-config module)

    • gcr-3: contains the base encryption stuff

    • gcr-ui-3: contains code which interacts with GTK (widget and other related code)

    GcrSecureEntryBuffer is part of gcr-ui-3, so you should use that for adding the necessary flags.