2014-11-06 106 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