@8Observer8, @SGaist, @jsulm :
qt 6.6.2, emscripten: 3.1.37, ubuntu: 22.04
i am trying to compile the code for loading obj using assimp (for wasm). I get error qglobal.h: fatal error: 'type_traits' file not found.
My question is how to avoid this error?
/home/neo/Desktop/softwares/qt662_wasm/qt6/qtbase/src/corelib/global/qglobal.h:13:12: fatal error: 'type_traits' file not found
# include <type_traits>
However, I have /usr/include/c++/11/type_traits file. The file at /home/neo/Desktop/softwares/qt662_wasm/qt6/qtbase/src/corelib/global/qglobal.h reads:
#ifdef __cplusplus
# include <type_traits>
...
#endif
I think this problem has been faced before as documented in type_traits-file-not-found-while-building-qwt6-1-4. This is occuring if we compile for wasm too.
My main.cpp and test.pro are as below. I use assimp to load 3D meshes, which I have built using emscripten using the following steps:
git clone https://github.com/assimp/assimp.git
cd assimp && mkdir build && cd build
emcmake cmake ..
emmake make
main.cpp
#include <QtWidgets/QApplication>
//#include <QtGui/QOpenGLWidget>
#include <QOpenGLWidget>
#include <QtWidgets/QMessageBox>
//#include <QtGui/QOpenGLBuffer>
#include <QOpenGLBuffer>
//#include <QtGui/QOpenGLShaderProgram>
#include <QOpenGLShaderProgram>
#include <QtGui/QMatrix4x4>
#include <QtGui/QVector3D>
#include <QtCore/QDebug>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <QMouseEvent>
//#include <cstdarg>
class OpenGLWidget : public QOpenGLWidget {
public:
OpenGLWidget(QWidget *parent = nullptr) : QOpenGLWidget (parent) {
setWindowTitle("Qt load obj using shaders");
resize(600, 600);
}
private:
QOpenGLBuffer m_vertPosBuffer;
QOpenGLShaderProgram m_program;
int m_numVertices;
void initializeGL() override {
glClearColor(0.1f, 0.1f, 0.1f, 1.f);
glEnable(GL_DEPTH_TEST);
Assimp::Importer importer;
const char *path = "./REC-3MxwG6i6jfG8ig2.obj";
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;
}
m_vertPosBuffer.create();
m_vertPosBuffer.bind();
m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions));
const char *vertShaderSrc =
"#version 330 core\n"
"in vec3 aPosition;"
"uniform mat4 uModelMatrix;"
"void main()"
"{"
" gl_Position = uModelMatrix * vec4(aPosition, 1.0);"
"}";
const char *fragShaderSrc =
"#version 330 core\n"
"out vec4 fragColor;"
"void main()"
"{"
" fragColor = vec4(0.8, 0.2, 0.2, 1.0);"
"}";
m_program.create();
m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vertShaderSrc);
m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragShaderSrc);
m_program.link();
QMatrix4x4 modelMatrix;
modelMatrix.scale(0.5);
m_program.bind();
m_program.setUniformValue("uModelMatrix", modelMatrix);
m_program.setAttributeBuffer("aPosition", GL_FLOAT, 0, 3);
m_program.enableAttributeArray("aPosition");
}
void resizeGL(int w, int h) override {
glViewport(0, 0, w, h);
}
void paintGL() override {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, m_numVertices);
}
};
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
OpenGLWidget w;
w.show();
return a.exec();
}
test.pro
QT += core gui opengl openglwidgets
# Add the path to the Assimp library directory if needed
LIBS += -L/home/neo/Desktop/softwares/assimp/build/lib
# Link against the Assimp library
LIBS += -lassimp
# Add the path to the Assimp header files if needed
INCLUDEPATH += /home/neo/Desktop/softwares/assimp/include
INCLUDEPATH += /usr/include/x86_64-linux-gnu
INCLUDEPATH += /usr/include/linux
# Add include path to Emscripten's C++ standard library headers
INCLUDEPATH += /home/neo/Desktop/softwares/emsdk/upstream/emscripten/system/include
# the system's C++ standard library
QMAKE_CXXFLAGS += -stdlib=libstdc++
# Additional compiler options for Assimp
QMAKE_CXXFLAGS += -Wno-deprecated-declarations
TEMPLATE = app
TARGET = AssimpExample
CONFIG += c++11
SOURCES += main.cpp