我在 Ubuntu 13.04 上尝试使用gsettingsschema.h 库中的函数
这是我的 .pro 文件
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 报告:
-lgio-2.0 -lgobject-2.0 -lglib-2.0
这对我来说听起来不错。
在我的程序中,我同时使用了 gio/gio.h 和 gio/gsettingsschema.h 库。编译器能够从 gio.h 中找到函数(如 g_settings_new_full()),但无法从 gsettingsschema.h 中找到函数
我收到如下错误:
undefined reference to 'g_settings_schema_source_get_default()'
这里发生了什么事?
编辑:完整编译输出(从 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 确切文件名:
/usr/lib/i386-linux-gnu/libgio-2.0.so.0.3600.0
有用的命令:
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