0

I'm on Ubuntu 13.04 trying to use functions from the gsettingsschema.h library

This is my .pro file

QT+=core
QT-=gui
TARGET=gsettings_test
CONFIG+=console
CONFIG-=app_bundle

CONFIG+=link_pkgconfig
PKGCONFIG+=gio-2.0

TEMPLATE=app

SOURCES+=main.cpp

pkg-config --libs gio-2.0 reports :

-lgio-2.0 -lgobject-2.0 -lglib-2.0

which sounds good to me.

In my program I use both the gio/gio.h and gio/gsettingsschema.h libraries. The compiler is able to find the functions from gio.h (like g_settings_new_full()) but it is not able to find the functions from gsettingsschema.h

I get an error like:

undefined reference to 'g_settings_schema_source_get_default()'

What's happening here?

EDIT: Full compilation output (as reported from Qt Creator):

01:46:09: Running steps for project gsettings_test...
01:46:09: Starting: "/usr/bin/qmake" /home/alex/Qt/gsettings_test/gsettings_test.pro -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug
01:46:09: The process "/usr/bin/qmake" exited normally.
01:46:09: Starting: "/usr/bin/make" 
g++  -o gsettings_test main.o   -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lQt5Core -lpthread 
main.o: In function `gsettings_get(QString, QString)':
/home/alex/Qt/build-gsettings_test-Desktop-Debug/../gsettings_test/main.cpp:17: undefined reference to `g_settings_schema_source_get_default()'
/home/alex/Qt/build-gsettings_test-Desktop-Debug/../gsettings_test/main.cpp:17: undefined reference to `g_settings_schema_source_ref(_GSettingsSchemaSource*)'
/home/alex/Qt/build-gsettings_test-Desktop-Debug/../gsettings_test/main.cpp:19: undefined reference to `g_settings_schema_source_lookup(_GSettingsSchemaSource*, char const*, int)'
collect2: error: ld returned 1 exit status
make: *** [gsettings_test] Error 1
01:46:10: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project gsettings_test (kit: Desktop)
When executing step 'Make'
01:46:10: Elapsed time: 00:01.

Libgio exact filename:

/usr/lib/i386-linux-gnu/libgio-2.0.so.0.3600.0

Helpful command:

alex@MaD-pc:~$ sudo ldconfig -v | grep gio
[sudo] password for alex: 
/sbin/ldconfig.real: Can't stat /lib/i686-linux-gnu: No such file or directory
/sbin/ldconfig.real: Can't stat /usr/lib/i686-linux-gnu: No such file or directory
/sbin/ldconfig.real: Path `/lib/i386-linux-gnu' given more than once
/sbin/ldconfig.real: Path `/usr/lib/i386-linux-gnu' given more than once
    libgiomm-2.4.so.1 -> libgiomm-2.4.so.1.3.0
    libgio-2.0.so.0 -> libgio-2.0.so.0.3600.0
hytromo
  • 1,501
  • 2
  • 27
  • 57
  • How does the linker call look like? – Frank Osterfeld Aug 14 '13 at 20:12
  • What is the **exact** version of your gio libs? Might be that yours are too old. – Greenflow Aug 14 '13 at 20:18
  • @FrankOsterfeld That's the command used for compilation: `g++ -o gsettings_test main.o -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lQt5Core -lpthread` @Greenflow you again :) I'm on Ubuntu 13.04, so I don't think that my gio libs are old (http://i.imgur.com/53b4Nao.png) – hytromo Aug 14 '13 at 20:36
  • Hmm, yes.. btw.. your compiler finds your functions just fine. Compilation is done. The linker is the problem. Means he does not find the shared lib. Or the lib is too old and does not contain the function. Perhaps you give us a little more of your compiler output. Just one "undefined reference" is nice for reading, but hard for debugging. :-) – Greenflow Aug 14 '13 at 20:53
  • Question updated (did I post what you need?). – hytromo Aug 14 '13 at 22:48
  • I does not look too bad at least. Just one lib seems to be the problem. Far too often show linker error hard to read text blobs. :-) – Greenflow Aug 14 '13 at 23:23
  • Please give me the exact filename of your libgio. Look like this: libgio-2.0.so.0.3102.0. I still think that you have an incompatible libgio. I know, your unbuntu is fairly recent. But the linker does not complain, that it does not find the lib at all, but only for a few selected functions. Do you have more than one libgio installed? What do you see when you do as root: 'ldconfig -v | grep gio'? – Greenflow Aug 15 '13 at 00:01
  • Wanna still try some desperate stuff? But maybe we really should use the chat now. :-) – Greenflow Aug 15 '13 at 21:40

1 Answers1

3

I know this is rather outdated, but I recently had the same issue, found this question without any real answer and was finally able to solve it. So hopefully this will help others having the same issue.

The problem was related to different function name mangling between C and C++, so if you include the GLib files from C++ code, you will get the undefined reference errors.

The solution was to change my includes from

#include <gio/gio.h>
#include <glib.h>

to

extern "C" {
#include <gio/gio.h>
#include <glib.h>
}

After that, compilation (and linking!) worked just fine.