【问题标题】:Program crashed while compiling and executing Qt5 project with Assimp使用 Assimp 编译和执行 Qt5 项目时程序崩溃
【发布时间】:2015-01-03 01:05:15
【问题描述】:

我想实现一个可以使用 Assimp(link of Assimp) 将 3D 模型加载到 OpenGL 中的程序。

我的 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;
}

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

正在启动 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 崩溃

我尝试调试,但断点似乎不起作用。

我删除了一些代码,只声明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;
}

程序可以再次运行!

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

【问题讨论】:

  • 我的编译器是 Microsoft Visual C++ Compiler 10.0

标签: c++ qt qt-creator assimp


【解决方案1】:

将动态库添加到 Qt 的 debug/release(根据您在 debug 中的编译输出)目录中。 没有引用代码的程序:

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

会起作用,因为它不调用动态库中的函数,这就是它被称为动态库的原因。
也写:

LIBS += -L/path not -l

【讨论】:

  • 我将动态库添加到调试和发布目录。我尝试在调试和发布模式下编译。但问题并没有解决。
  • 顺便说一下,ReadFileGetErrorStringAssimp::Importer 的类函数,如果没有Assimp::Importer 对象,我无法使用这些函数。 LIBS += -l 跟随静态库文件而不是目录。 Qt 会自动将.lib 添加到文件名中。
  • 您是否也添加了 dll 文件?另外,您是否确定您使用的是正确架构(32/64 位)的库?
  • 抱歉我的回复晚了。我添加了 dll 文件,我确信我将这些库用于正确的架构。更何况我建项目后运行exe文件,报错:The application was unable to start correctly (0xc000007b)
  • 基于 Windows 错误代码Doc,此错误代码表示:0xC000007B STATUS_INVALID_IMAGE_FORMAT:这很好地表明 32 位应用程序试图加载 64 位 DLL。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多