Undefined reference to `g_memdup2'

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.