我有蜜蜂试图让assimp在QT 5.2中运行,以便导入一些3D对象,但是林先生(我相信)链接器有问题。
我通过cmake安装了它,首先从此处http://sourceforge.net/projects/assimp/files/assimp-3.0/下载源文件,然后使用cmake进行编译和安装。
然后,我尝试运行它们在文档中提供的示例
#include <assimp/cimport.h> // Plain-C interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
bool DoTheImportThing( const char* pFile)
{
// Start the import on the given file with some example postprocessing
// Usually - if speed is not the most important aspect for you - you'll t
// probably to request more postprocessing than we do in this example.
const aiScene* scene = aiImportFile( pFile,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
// If the import failed, report it
if( !scene)
{
// DoTheErrorLogging( aiGetErrorString());
return false;
}
return true;
}
但是当尝试编译这段代码时,我得到了错误
error: undefined reference to `aiImportFile'
error: collect2: error: ld returned 1 exit status
我正在使用32位Linux Mint。有人知道为什么不链接吗?我应该使用特定标志使用cmake进行编译吗?我无法在周围的任何帖子中找到任何特殊标志。
谢谢!
最佳答案
我终于解决了!显然,QT具有导入外部库的工具。我只需要右键单击该项目,单击添加库,然后添加位于/user/local/libassimp.a的文件
这将以下行添加到我的.pro文件中:
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/release/ -lassimp
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/debug/ -lassimp
else:unix: LIBS += -L$$PWD/../../../../../usr/local/lib/ -lassimp
INCLUDEPATH += $$PWD/../../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../../usr/local/include
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/release/libassimp.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/debug/libassimp.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/release/assimp.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/debug/assimp.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../../../../usr/local/lib/libassimp.a
可能有一种更优雅的编码方式,但至少它能起作用。
关于c++ - 使用QT的未定义引用AIImportfile(assimp),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22199316/