My compiler reports this undefined reference to openWallet(..)
function. As you can see I have linked responding libraries -L/usr/lib -lkdeui -kdecore -lkparts
.
Error:
password.cpp:(.text+0x29): undefined reference to `KWallet::Wallet::openWallet(QString const&, unsigned long long, KWallet::Wallet::OpenType)'
Compile command:
g++ -Wl,-O1 -Wl,-rpath-link,/usr/lib/x86_64-linux-gnu -o password_client "ALL *.o FILES" -L/usr/lib -lkdecore -lkdeui -lkparts -lglib-2.0 -L/usr/X11R6/lib64 -L/usr/lib/x86_64-linux-gnu -lGL -lpthread
Same error is reported by QtCreator. .pro
file contains
LIBS += -lkdecore \
-lkdeui \
-lkparts
I have all that required libs installed. Proof:
Output of nm -D /usr/lib/libkdeui.so | grep openWallet
is :
000000000032df70 T _ZN7KWallet6Wallet10openWalletERK7QStringmNS0_8OpenTypeE
As you can see there is that funcion in libkdeui.so file. ^^
I have installed libraries with:
sudo apt-get install kdelibs5-dev libkparts4
Can someone tell me what am I doing wrong? Where is the mistake?
SSCCE:
#include <QCoreApplication>
#include <KWallet/Wallet>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
using namespace KWallet;
Wallet* wallet = Wallet::openWallet(Wallet::LocalWallet(), 0);
return a.exec();
}
.pro
file:
QT += core
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp
LIBS += -lkdeui -lkdecore -lkparts
INCLUDEPATH += /usr/include/KDE \
/usr/include/KDE/KWallet
Compilation:
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_DBUS_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/KDE -I/usr/include/KDE/KWallet -ITDIR/include/QtGui -ITDIR/include -I. -o main.o main.cpp
g++ -m64 -Wl,-O1 -o untitled main.o -L/usr/lib -L/usr/X11R6/lib64 -lkdeui -lkdecore -lkparts -L/usr/lib/x86_64-linux-gnu -lGL -lpthread
Your main issue is that you are mixing up Qt 5 with KDE Frameworks 5. That is not going to fly like that. See this yourself:
The fix is relatively simple:
Naturally, if you move onto KF5, you will also need to change the includepaths to:
You will need to link against that library should you be using Qt 5 and KF 5. Basically, you were using kde 4, as kdeui is a KDE 4 library. You can check that yourself by issuing the following command:
In short, the
WId
wasunsigned long
in the kdeui library since that is what was used for this on X11 platforms, whereas the Qt 5 mix may have confused thequintptr
in for theWId
, somehow. While Qt 4's WId was different for different platforms, Qt 5's WId isquintptr
, so that is clearer.If you plan to use Qt 4 with KDE 4, your initial code is fine, but you need to make sure that you run Qt 4's qmake in that case as opposed to Qt 5's. This can be either by using qtchooser or running the proper qmake binary directly.
qmake --version
is always your friend to verify the version that is being run. On my Debian and Archlinux, the corresponding qmake binary is calledqmake-qt4
.On a side note, it is strange that you add the
widgets
module, but you wish to remove thegui
, whereas the former depends on the latter. Having seen thewidgets
module used in the project file, my opinion is even more clear that you probably wish to use the Qt 5 and KF 5 combination at this point in time.Here is my working Qt 5 and KF 5 test snippet:
main.cpp
main.pro
Build
For this to work on Ubuntu, you will need to install the following package which was added to Utopic (14.10):
Unfortunately, Trusty Tahr (14.04) did not have this available, but you might be able to backport it if you wish to.