外部库在Qt Creator中引发未定义的参考错误 [英] External library throws undefined reference errors in Qt Creator
问题描述
我在使用外部库/SDK时遇到一些问题. 我正在Ubuntu和Oculus Rift SDK下使用Qt Creator. Oculus Rift SDK由依赖于平台的lib文件和一些c ++源代码组成.请注意,我非常怀疑我的问题在任何方面都是Oculus SDK或Xinerama所特有的.
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.
我使用向导并将SDK添加为外部库.结果就是这样:
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
现在,我应该可以从SDK调用方法了.但是,这是我在编译时遇到的错误之一:
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'
我已经尝试过将此行添加到我的.pro文件中,但没有做任何更改:
I already tried adding this line to my .pro file but nothing changed:
unix:LIBS += -lXinerama
如果我包含与OVR_Linux_HMDDevice.cpp完全相同的头文件,
If I include the very same header file as OVR_Linux_HMDDevice.cpp does,
#include <X11/extensions/Xinerama.h>
我可以从我的代码中成功调用XineramaIsActive.因此,显然,只有外部源代码才能访问该方法.
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?
推荐答案
此处的链接顺序很重要.您需要确保在-lovr
选项之后 之后添加-lXinerama
选项.当您将它们添加到.pro
文件中时,qmake应该保留它们的顺序.
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.
这篇关于外部库在Qt Creator中引发未定义的参考错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!