2014-11-06 108 views
1

我想实现一个程序,可以使用Assimp(link of Assimp)将3D模型加载到OpenGL中。程序在使用Assimp编译和执行Qt5项目时崩溃了

我的Qt版本是5.3.2。 我使用Qt Creator和修改.pro文件导入Assimp库:

INCLUDEPATH += H:\Study\assimp-3.1.1-win-binaries\assimp-3.1.1-win-binaries\include\assimp 
LIBS += -lH:\Study\assimp-3.1.1-win-binaries\assimp-3.1.1-win-binaries\lib32\assimp 

然后我试着在我的程序读取box.obj

#include <scene.h> 
#include <postprocess.h> 
#include <Importer.hpp> 

int main(){ 
    Assimp::Importer importer; 

    const aiScene* scene = importer.ReadFile("box.obj", NULL); 

    if (!scene) 
    { 
     qDebug() << "Error loading file: (assimp:) " << importer.GetErrorString(); 
     return false; 
    } 

    .....// Other code to create a window 

    return 0; 
} 

然后编译完成没有错误。 然后程序刚刚启动后崩溃。

Starting G:\QtProject\QtTest\build-MyOpenGL-Desktop_Qt_5_3_MSVC2010_OpenGL_32bit-Debug\debug\MyOpenGL.exe...

G:\QtProject\QtTest\build-MyOpenGL-Desktop_Qt_5_3_MSVC2010_OpenGL_32bit-Debug\debug\MyOpenGL.exe crashed

我尝试调试但断点看起来不起作用。

我删除一些代码,只需要声明scene

#include <scene.h> 
#include <postprocess.h> 
#include <Importer.hpp> 

int main(){ 
    //Assimp::Importer importer; 

    const aiScene* scene; // = importer.ReadFile("box.obj", NULL); 

    /*if (!scene) 
    { 
     qDebug() << "Error loading file: (assimp:) " << importer.GetErrorString(); 
     return false; 
    }*/ 

    .....// Other code to create a window 

    return 0; 
} 

程序可以再次运行!

我现在很困惑。谁能帮我?

+0

我的编译器是微软的Visual C++编译器10.0 – Paler 2014-11-06 13:42:34

回答

2

将动态库添加到Qt的调试/发行版(根据您在调试中的编译输出)。 无引号代码程序:

ReadFile("box.obj", NULL); 
GetErrorString(); 

会工作,因为它不要求在动态库中的函数,这就是为什么它被称为动态库。
还写:

LIBS += -L/path not -l 
+0

我添加动态库调试版本和发布目录。我尝试在调试和发布模式下进行编译。但问题没有解决。 – Paler 2014-11-07 01:51:17

+0

顺便说一句,'ReadFile'和'GetErrorString'是'Assimp :: Importer'的类函数,我不能在没有'Assimp :: Importer'对象的情况下使用这些函数。 LIBS + = -l遵循静态库文件而不是目录。 Qt会自动为文件名添加'.lib'。 – Paler 2014-11-07 01:58:59

+0

你也添加了dll文件吗?另外你是否确定你正在使用正确的架构(32/64位)的库? – 2014-11-07 05:16:43