Undefined reference to `g_memdup2'

I am trying to build a spinbox demo application with GTK3. I am facing the following error:

**/usr/bin/ld: /Palomino1/lib/libpango-1.0.so: undefined reference to `g_memdup2'**

My GTK version 3.24.30, Glib version is 2.70, Pango is 1.48.10. My guess is this something to do with a version mismatch between Pango and glib. gmemdup2 migh have been deprecated or something like that. Any help on this?

Here is my code sample:

#include <gtk/gtk.h>
GtkAdjustment* createAdjustment();
int main(int argc, char **argv)
{
    GtkWidget *window;
    GtkListStore *liststore;
    GtkWidget *pWidget;
    GtkWidget *pLabel;
    GtkCellRenderer *column;
    GtkAdjustment* pAdjustment;
    double StepSize =1;
    int DecimalPlaces=1;
    int MaxChars=10;
	
    gtk_init(&argc, &argv);  
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    pAdjustment = createAdjustment();
    pWidget = gtk_spin_button_new(GTK_ADJUSTMENT(pAdjustment), StepSize, DecimalPlaces);
   
    //pWidget=gtk_spin_button_new_with_range(0, 10, 1);

    // Set the maximum length if specified
    if(MaxChars != 0)
    {
        gtk_entry_set_max_length(GTK_ENTRY(pWidget), MaxChars);
    }

    // Disable value wrap-around
    gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(pWidget), false);

    // Only allow numeric keystrokes
    gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(pWidget), true);
    
    //pLabel = gtk_label_new(NULL);
    //gtk_label_set_markup_with_mnemonic(GTK_LABEL(pLabel), "First");
    //gtk_widget_set_halign(pLabel,GTK_ALIGN_FILL);
    
    gtk_container_set_border_width(GTK_CONTAINER(window), 50);
    gtk_container_add (GTK_CONTAINER (window), pWidget); 
    // gtk_container_add (GTK_CONTAINER (window), pLabel);   
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
GtkAdjustment* createAdjustment()
{
	double Value =0;
	double Lower =0;
	double Upper=100;
	double StepSize=1;
	double ClimbSize=5;

	return(reinterpret_cast<GtkAdjustment*>(gtk_adjustment_new(Value, Lower, Upper, StepSize, ClimbSize, 0)));
}

If I search for that gmemdup2 symbol in my GTK build output dump, I get this:

~:$ grep -r “g_memdup2” .

Binary file ./bin/hb-subset matches
Binary file ./lib/libgobject-2.0.so.0.7000.0 matches
Binary file ./lib/girepository-1.0/GLib-2.0.typelib matches
Binary file ./lib/libgio-2.0.so.0.7000.0 matches
Binary file ./lib/libpango-1.0.so.0.4800.10 matches
Binary file ./lib/libglib-2.0.so.0.7000.0 matches
Binary file ./lib/libgirepository-1.0.so.1.0.0 matches
Binary file ./lib/libpangoft2-1.0.so.0.4800.10 matches
./include/glib-2.0/glib/gstrfuncs.h:GLIB_DEPRECATED_IN_2_68_FOR (g_memdup2)
./include/glib-2.0/glib/gstrfuncs.h:gpointer g_memdup2 (gconstpointer mem,
./share/gobject-introspection-1.0/tests/foo.c: return (RegressFooBoxed *)g_memdup2 (boxed, sizeof (RegressFooBoxed));
./share/gobject-introspection-1.0/tests/foo.c: return (RegressFooDBusData *)g_memdup2 (boxed, sizeof (RegressFooDBusData));
./share/gobject-introspection-1.0/tests/foo.c: return (RegressFooBRect *)g_memdup2 (boxed, sizeof (RegressFooBRect));
./share/gobject-introspection-1.0/tests/foo.c: return (RegressFooBUnion *)g_memdup2 (boxed, sizeof (RegressFooBUnion));
./share/gobject-introspection-1.0/tests/foo.c: return (RegressFooHidden *)g_memdup2 (boxed, sizeof (RegressFooHidden));
./share/gir-1.0/GLib-2.0.gir: Use g_memdup2() instead, as it accepts a #gsize argument
./share/gir-1.0/GLib-2.0.gir:

You sure you are building against Glib 2.70? I’d double check your linker. g_memdup2 should be there with any glib 2.68+ version.

Yes I am linking against glib 2.70 and the symbol is present:

ll | grep “libglib”
lrwxrwxrwx 1 parallels parallels 16 Oct 4 15:41 libglib-2.0.so → libglib-2.0.so.0*
lrwxrwxrwx 1 parallels parallels 23 Oct 4 15:41 libglib-2.0.so.0 → libglib-2.0.so.0.7000.0*
-rwxr-xr-x 1 parallels parallels 1520160 Oct 4 15:36 libglib-2.0.so.0.7000.0*
parallels@parallels-Parallels-Virtual-Platform:/myGTKDir/lib$ nm -D ./libglib-2.0.so.0 | grep “memdup”
0000000000084250 T g_memdup
00000000000842a0 T g_memdup2

does this sequence matter?

-L/Palomino1/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

As Jordan says, this looks very much like:

  • Your Pango library was built against GLib ≥ 2.68
  • Your project is being built (or just linked) against GLib < 2.68

g_memdup2() was added in GLib 2.68, and there’s nothing odd about it as a symbol. It’s defined the same way as every other GLib symbol.

From the output you’ve provided (though providing the full compiler/linker commands and some idea of how your prefix is laid out would be a lot more helpful), it looks like you’re building things with some custom prefixes. It’s most likely that your project is being linked against a different version of GLib from the one in your prefix — probably your system installation of GLib, which will be older. You’ll need to ensure you’re passing the right -L options to all the linker commands. You may also have to set LD_LIBRARY_PATH when you get your project built, in order to run it.

Typically, people do this by using pkg-config and/or a build tool like Meson, rather than (as it appears you are doing) writing the compilation commands manually, which is error prone.

Good luck!

I can see that my Pango lib is referring to the correct glib that I built:

929984:	find library=libglib-2.0.so.0 [0]; searching
929984:	 search path=/myDir/lib		(LD_LIBRARY_PATH)
929984:	  trying file=/myDir/lib/libglib-2.0.so.0

lrwxrwxrwx 1 parallels root 16 Oct 7 14:57 libglib-2.0.so → libglib-2.0.so.0*
lrwxrwxrwx 1 parallels root 23 Oct 7 14:57 libglib-2.0.so.0 → libglib-2.0.so.0.7000.0*
-rwxr-xr-x 1 parallels root 1520160 Oct 7 14:57 libglib-2.0.so.0.7000.0*

I was making a mistake in the build command, it should have been this:

g++ pkg-config --cflags gtk+-3.0 -Wall -o spintest sampleSpinBOx.cpp pkg-config --libs gtk+-3.0

I have a $PKG_CONFIG_PATH set to “/my_prefix_dir/lib/pkgconfig”

I also have LD_LIBRARY_PATH set to “/my_prefix_dir/lib/”

I think because of my mistake in the command the linker was not able to find my GTK libraries and was linking with old version of them from system as Philip suggested.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.