2

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?

derp
  • 65
  • 1
  • 7

1 Answers1

4

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.

Community
  • 1
  • 1
rubenvb
  • 69,525
  • 30
  • 173
  • 306
  • I indeed added -lXinerama before -lovr. After moving it down and adding another library, it finally compiled. Thank you so much! But I realize I am lacking some very basic understanding here: Intuition tells me it should come first, so why is it the other way round? – derp Jan 13 '14 at 16:15
  • 2
    Dependencies are resolved left to right. So if you do `-la -lb -lc`, `libb` will be used to resolve undefined symbols in `liba`, and `libc` will be used to resolve dependencies in `liba` and `libb`. If, say, `liba` depends on `libb`, `libb` depends on `libc`, and `libc` depends on `liba`... you will have to "link" `liba` twice: `-la -lb -lc -la`. This leads to funny situations. Note that GNU binutils has the options `--begin-group` and `--end-group` which do search circularly until dependencies are resolved. In principle though, this circular search could lead to a deadlock. – rubenvb Jan 13 '14 at 16:22
  • Thank you again! Thinking about it, this makes a lot more sense. – derp Jan 13 '14 at 16:36