如何为 Qt6 MinGW 64 位设置 Assimp 以在 WebAssembly 上运行

问题描述 投票:0回答:1

接下来的步骤对我有用(在我将

C:\emsdk\upstream\emscripten
添加到 Path 变量之后):

> cd assimp-5.2.5 && mkdir build && cd build
> emcmake cmake ..
> emmake make

这些命令生成了

libassimp.a
库:

我尝试在 Qt Creator 中设置这个库,如下所示:

INCLUDEPATH += "E:/libs/assimp-5.2.5/include"
LIBS += -L"E:/libs/assimp-5.2.5/build/lib"
LIBS += -lassimp

我遇到了这个错误:

error: 'assimp/config.h' file not found
。我通过将此文件
E:\libs\assimp-5.2.5\build\include\assimp\config.h
复制到此目录解决了此错误:
E:\libs\assimp-5.2.5\include\assimp

问题:

:-1: error: [Makefile:69: .\load-with-assimp-wasm-opengles2-qt6-cpp.js] Error 1
但是我已经使用 OpenGL ES 2.0 到 WASM 构建了另一个示例,没有出现问题。

编译器输出:

15:56:34: Running steps for project load-with-assimp-wasm-opengl2-qt6-cpp...
15:56:34: Starting: "C:\Qt\6.7.0\wasm_singlethread\bin\qmake.bat" E:\_Projects\LoadingModels\load-with-assimp-wasm-opengl2-qt6-cpp\load-with-assimp-wasm-opengl2-qt6-cpp.pro -spec wasm-emscripten "CONFIG+=debug" "CONFIG+=qml_debug"
15:56:36: The process "C:\Qt\6.7.0\wasm_singlethread\bin\qmake.bat" exited normally.
15:56:36: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -f E:/_builds/build-load-with-assimp-wasm-opengl2-qt6-cpp-WebAssembly_Qt_6_7_0_single_threaded-Debug/Makefile qmake_all
mingw32-make: Nothing to be done for 'qmake_all'.
15:56:36: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
15:56:36: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -j4
C:\Qt\6.7.0\mingw_64\bin\qmake6.exe -install sed -e s/@APPNAME@/load-with-assimp-wasm-opengl2-qt6-cpp/g -e s/@APPEXPORTNAME@/load_with_assimp_wasm_opengl2_qt6_cpp_entry/g -e s/@PRELOAD@//g C:/Qt/6.7.0/wasm_singlethread/plugins/platforms/wasm_shell.html > E:/_builds/build-load-with-assimp-wasm-opengl2-qt6-cpp-WebAssembly_Qt_6_7_0_single_threaded-Debug/load-with-assimp-wasm-opengl2-qt6-cpp.html
copy /y C:\Qt\6.7.0\wasm_singlethread\plugins\platforms\qtloader.js E:\_builds\build-load-with-assimp-wasm-opengl2-qt6-cpp-WebAssembly_Qt_6_7_0_single_threaded-Debug
copy /y C:\Qt\6.7.0\wasm_singlethread\plugins\platforms\qtlogo.svg E:\_builds\build-load-with-assimp-wasm-opengl2-qt6-cpp-WebAssembly_Qt_6_7_0_single_threaded-Debug
        1 file(s) copied.
        1 file(s) copied.
em++ -s 'ASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js' -s WASM=1 -s MAX_WEBGL_VERSION=2 -s ERROR_ON_UNDEFINED_SYMBOLS=1 --bind -s FETCH=1 -s MODULARIZE=1 -s WASM_BIGINT=1 -s STACK_SIZE=5MB -g2 -s WASM=1 -s MAX_WEBGL_VERSION=2 -s ERROR_ON_UNDEFINED_SYMBOLS=1 --bind -s FETCH=1 -s MODULARIZE=1 -s WASM_BIGINT=1 -s STACK_SIZE=5MB -s DEMANGLE_SUPPORT=1 --profiling-funcs -s EXPORTED_RUNTIME_METHODS=UTF16ToString,stringToUTF16,JSEvents,specialHTMLTargets,FS -s EXPORT_NAME=load_with_assimp_wasm_opengl2_qt6_cpp_entry -sALLOW_MEMORY_GROWTH -s INITIAL_MEMORY=50MB C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledFreetype.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledLibpng.a -o .\load-with-assimp-wasm-opengl2-qt6-cpp.js   @object_script.load-with-assimp-wasm-opengl2-qt6-cpp.js
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(AssbinLoader.cpp.o): undefined symbol: uncompress
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateInit_
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateInit2_
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflate
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflate
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflate
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateReset
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateSetDictionary
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateEnd
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateEnd
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflateInit2_
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(unzip.c.o): undefined symbol: get_crc_table
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(unzip.c.o): undefined symbol: crc32
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(Compression.cpp.o): undefined symbol: inflate
wasm-ld: error: E:/libs/assimp-5.2.5/build/lib\libassimp.a(unzip.c.o): undefined symbol: crc32
em++: error: 'C:/emsdk/upstream/bin\wasm-ld.exe -o .\load-with-assimp-wasm-opengl2-qt6-cpp.wasm C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledFreetype.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledLibpng.a main.obj load-with-assimp-wasm-opengl2-qt6-cpp.js_plugin_import.obj -LE:/libs/assimp-5.2.5/build/lib E:/libs/assimp-5.2.5/build/lib\libassimp.a C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/QWasmIntegrationPlugin_resources_1/.rcc/qrc_wasmfonts_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/QWasmIntegrationPlugin_resources_2/.rcc/qrc_wasmwindow_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Gui_resources_1/.rcc/qrc_qpdf_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Gui_resources_2/.rcc/qrc_gui_shaders_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/plugins/platforms/libqwasm.a C:/Qt/6.7.0/wasm_singlethread/plugins/iconengines/libqsvgicon.a C:/Qt/6.7.0/wasm_singlethread/plugins/imageformats/libqgif.a C:/Qt/6.7.0/wasm_singlethread/plugins/imageformats/libqico.a C:/Qt/6.7.0/wasm_singlethread/plugins/imageformats/libqjpeg.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledLibjpeg.a C:/Qt/6.7.0/wasm_singlethread/plugins/imageformats/libqsvg.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6Svg.a C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Widgets_resources_1/.rcc/qrc_qstyle_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Widgets_resources_2/.rcc/qrc_qstyle1_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Widgets_resources_3/.rcc/qrc_qstyle_fusion_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/objects-Release/Widgets_resources_4/.rcc/qrc_qmessagebox_init.cpp.o C:/Qt/6.7.0/wasm_singlethread/lib/libQt6OpenGLWidgets.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6OpenGL.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6Widgets.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6Gui.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledHarfbuzz.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledFreetype.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledLibpng.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6Core.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledZLIB.a C:/Qt/6.7.0/wasm_singlethread/lib/libQt6BundledPcre2.a -LC:\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten --whole-archive -lfetch -lembind-rtti --no-whole-archive -lGL-webgl2 -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr C:\Users\8OBSER~1\AppData\Local\Temp\tmpl78yuxdvlibemscripten_js_symbols.so --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=__cxa_demangle --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=malloc --export=free --export=__wasm_call_ctors --export-table -z stack-size=5242880 --initial-memory=52428800 --no-entry --max-memory=2147483648 --stack-first' failed (returned 1)
mingw32-make: *** [Makefile:69: .\load-with-assimp-wasm-opengl2-qt6-cpp.js] Error 1
15:56:50: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project load-with-assimp-wasm-opengl2-qt6-cpp (kit: WebAssembly Qt 6.7.0 (single-threaded))
When executing step "Make"
15:56:50: Elapsed time: 00:16.

加载-with-assimp-wasm-opengles2-qt6-cpp.pro

QT += core gui openglwidgets widgets

win32: LIBS += -lopengl32

INCLUDEPATH += "E:/libs/assimp-5.2.5/include"
LIBS += -L"E:/libs/assimp-5.2.5/build/lib"
LIBS += -lassimp

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000

SOURCES += \
    main.cpp

主.cpp

#include <QtCore/QDebug>
#include <QtGui/QMatrix4x4>
#include <QtGui/QVector3D>
#include <QtGui/QOpenGLFunctions>
#include <QtOpenGL/QOpenGLBuffer>
#include <QtOpenGL/QOpenGLShaderProgram>
#include <QtOpenGLWidgets/QOpenGLWidget>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>

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

class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
{
public:
    OpenGLWidget()
    {
        setWindowTitle("OpenGL ES 2.0, Qt6, C++");
        resize(380, 380);
    }

private:
    QOpenGLBuffer m_vertPosBuffer;
    QOpenGLShaderProgram m_program;
    int m_numVertices;
    QMatrix4x4 m_modelMatrix;

    void initializeGL() override
    {
        initializeOpenGLFunctions();
        glClearColor(0.1f, 0.1f, 0.1f, 1.f);
        glEnable(GL_DEPTH_TEST);

        Assimp::Importer importer;
        const char *path = "assets/models/plane-blender.dae";
        const aiScene *scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
        if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
        {
            qDebug() << "Assimp Error:" << importer.GetErrorString();
            QMessageBox::critical(this, "Assimp Error:", importer.GetErrorString());
            return;
        }

        m_numVertices = scene->mMeshes[0]->mNumVertices;
        float vertPositions[m_numVertices * 3];
        int vertPosIndex = 0;
        for (int i = 0; i < m_numVertices; i++)
        {
            vertPositions[vertPosIndex++] = scene->mMeshes[0]->mVertices[i].x;
            vertPositions[vertPosIndex++] = scene->mMeshes[0]->mVertices[i].y;
            vertPositions[vertPosIndex++] = scene->mMeshes[0]->mVertices[i].z;
           // qDebug() << scene->mMeshes[0]->mVertices[i].x << ", "
           //          << scene->mMeshes[0]->mVertices[i].y << ", "
           //           << scene->mMeshes[0]->mVertices[i].z;
           //  qDebug() << "\n";
        }
        m_vertPosBuffer.create();
        m_vertPosBuffer.bind();
        m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions));

        const char *vertShaderSrc =
            "attribute vec3 aPosition;"
            "uniform mat4 uModelMatrix;"
            "void main()"
            "{"
            "    gl_Position = uModelMatrix * vec4(aPosition, 1.0);"
            "}";
        const char *fragShaderSrc =
            "void main()"
            "{"
            "    gl_FragColor = vec4(0.5, 0.2, 0.7, 1.0);"
            "}";
        m_program.create();
        m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Vertex,
            vertShaderSrc);
        m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Fragment,
            fragShaderSrc);
        m_program.link();
    }

    void resizeGL(int w, int h) override
    {
        glViewport(0, 0, w, h);
    }

    void paintGL() override
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        m_modelMatrix.setToIdentity();
        m_modelMatrix.scale(0.5);
        m_program.bind();
        m_program.setUniformValue("uModelMatrix", m_modelMatrix);
        m_vertPosBuffer.bind();
        m_program.setAttributeBuffer("aPosition", GL_FLOAT, 0, 3);
        m_program.enableAttributeArray("aPosition");
        glDrawArrays(GL_TRIANGLES, 0, m_numVertices);
    }
};

int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
    QApplication app(argc, argv);
    OpenGLWidget w;
    w.show();
    return app.exec();
}
c++ qt webassembly assimp
1个回答
0
投票

我用这些命令构建了 zlib:

> cd zlib-1.3.1 && mkdir build && cd build
> emcmake cmake ..
> emmake make

libz.a
(245 KB) 已生成。

我是这样设置的:

LIBS += -L"E:\libs\zlib-1.3.1\lib"
LIBS += -lz

现在可以编译了。多谢。但我认为 Assimp 必须包括

zlib
libassimp.a
的大小为 89.3 MB。

我现在有这个错误:

我在使用 Assimp 从 Qt Resources 加载模式时遇到问题: 从 Qt Resources 加载 3D 模型。 Assimp 错误:没有找到适合文件格式的阅读器 我决定不使用 Qt Resources 来解决该问题。但现在我不知道如何解决WASM。

© www.soinside.com 2019 - 2024. All rights reserved.