简体   繁体   中英

External library throws undefined reference errors in Qt Creator

I have some problems with using an external library/SDK. I am using Qt Creator under Ubuntu with the Oculus Rift SDK. The Oculus Rift SDK consists of a platform dependent lib file and some c++ source code. Note that I highly doubt my problem is in any way specific to the Oculus SDK or Xinerama.

I used the wizard and added the SDK as an external library. This was the result:

unix:!macx: LIBS += -L$$PWD/../OculusSDK/LibOVR/Lib/Linux/Release/x86_64/ -lovr
INCLUDEPATH += $$PWD/../OculusSDK/LibOVR/Include
DEPENDPATH += $$PWD/../OculusSDK/LibOVR/Include
unix:!macx: PRE_TARGETDEPS += $$PWD/../OculusSDK/LibOVR/Lib/Linux/Release/x86_64/libovr.a

Now I should be able to call methods from the SDK. However, this is one of the errors I get while compiling:

/home/me/OculusSDK/LibOVR/Lib/Linux/Release/x86_64/libovr.a(OVR_Linux_HMDDevice.o):-1: In function `OVR::Linux::HMDDeviceFactory::EnumerateDevices(OVR::DeviceFactory::EnumerateVisitor&)':
OVR_Linux_HMDDevice.cpp:-1: error: undefined reference to `XineramaIsActive'

I already tried adding this line to my .pro file but nothing changed:

unix:LIBS += -lXinerama

If I include the very same header file as OVR_Linux_HMDDevice.cpp does,

#include <X11/extensions/Xinerama.h>

I can successfully call XineramaIsActive from my code. So apparently, it's just the external source code that has issues accessing the method.

Any ideas what changes I have to make to the build process for this to work?

Link order is important here. You need to make sure the -lXinerama option is added after the -lovr option. qmake should preserve the order of libraries as you add them in your .pro file.

See this answer for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM