0

我一直在尝试在 QT 5.2 中运行 assimp 以导入一些 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 编译吗?我无法在周围的任何帖子中找到任何特殊标志。

谢谢!

4

1 回答 1

0

我终于解决了!显然,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

可能有一种更优雅的编码方式,但至少它有效。

于 2014-03-05T15:01:58.773 回答