pipacs / o2

OAuth 2.0 for Qt
BSD 2-Clause "Simplified" License
317 stars 147 forks source link

Getting "unresolved resolved external symbol" error in the example apps #136

Closed Wardstein closed 3 years ago

Wardstein commented 3 years ago

Hi all,

I tried to build the library and the example applications. Building the lib itself works fine in VisualStudio 2019. Btw. I am working on windows 10.

In the top CMakeLists.txt I set the "o2_WITH_VIMEO" option to ON. When I want to build the Vimeo example app (also with the lib), I get errors with unresolved external symbols. public: __cdecl O2PollServer::O2PollServer(class QNetworkAccessManager *,class QNetworkRequest const &,class QByteArray const &,int,class QObject *)" " in function ""protected: void __cdecl O2::startPollServer(class QMap<class QString,class QVariant> const &)" Also for "O2PollServer::setInterval(int)", "O2PollServer::startPolling(void)", "O2Vimeo::O2Vimeo(class QObject *)". I first tried to implement my own auth class (like O2Vimeo), then I got a few different unresolved errors, but same picture.

I downloaded the master and run the cmake command: cmake -D CMAKE_PREFIX_PATH=C:\Qt\Qt5.12.3\5.12.3\msvc2015_64 -DBUILD_SHARED_LIBS=1 -Do2_WITH_KEYCHAIN=OFF .

Does anybody know what I did wrong or misconfigured? Or why the linker? does not find these symbols? Could it be that the linker does not find the o2.lib file?

Wardstein commented 3 years ago

Update:

With the Qt Creator -> Add lib to project, I added now the following lines to the vimeodemo.pro file:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../src/release/ -lo2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../src/debug/ -lo2

INCLUDEPATH += $$PWD/../../src
DEPENDPATH += $$PWD/../../src

This helped to remove the unresolved external symbols for the previous message. But now I get the message for vimeodemo.obj : error LNK2001: Unresolved external symbol ""public: static struct QMetaObject const O2::staticMetaObject" (?staticMetaObject@O2@@2UQMetaObject@@B)".

Why does this fail? Seems like something of QObject is not found?

Wardstein commented 3 years ago

After searching a lot on the internet, finding hints it must and normally IS an issue with __declspec(dllexport) and __declspec(dllimport) I dug through the lib code checking all the exports and then had a look at the o0export.h header. After I opened this file in the project of the vimeodemo, VisualStudio highlighted, that the defined(O2_SHARED_LIB) was not set. So also the hole O2_DLL_EXPORT define was not set and therefore no dllimport used! Just set the O2_SHARED_LIB in the preprocessor definitions and et voilà, is compiles successfully :)

Sorry for spamming here around, going to close this. Hopefully this helps someone in the future