【问题标题】:Undefined reference aiImportfile (assimp) using QT未定义的引用 aiImportfile (assimp) 使用 QT
【发布时间】:2014-04-07 14:28:39
【问题描述】:

我一直在尝试在 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 编译吗?我无法在周围的任何帖子中找到任何特殊标志。

谢谢!

【问题讨论】:

  • 您似乎没有与图书馆链接
  • 约阿希姆,我也是这么想的。 gumlym,您能否发布您项目的 CMakeLists.txt,或者如果您正在使用 qmake 编译,请发布 qmake 文件?
  • 嗨!是的,我也认为我没有与图书馆链接,我只是不知道如何解决这个问题。我刚刚编辑了我的问题并添加了 CMakeLists.txt
  • 库的CMakeLists.txt 没有帮助。我们需要知道的是如何构建你的项目。

标签: c++ linux qt cmake assimp


【解决方案1】:

我终于解决了!显然,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-05-18
    • 2017-03-22
    • 2014-11-11
    • 2013-04-04
    • 2014-06-24
    • 2021-11-30
    • 2015-05-14
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多