使用 emscripten 编译结构时出错

Error compiling structures with emscripten

我用 em++ 编译了以下代码:

struct Point6f{
float x0;
float y0;
float z0;
float x1;
float y1;
float z1;
};

struct containerBbox {
float x0;
float y0;
float z0;
float x1;
float y1;
float z1;
};

containerBbox createBbox(Point6f);

EMSCRIPTEN_BINDINGS(my_value_example) {
emscripten::value_array<Point6f>("Point6f")
            .element(&Point6f::x0)
            .element(&Point6f::y0)
            .element(&Point6f::z0)
            .element(&Point6f::x1)
            .element(&Point6f::y1)
            .element(&Point6f::z1);

emscripten::value_object<containerBbox>("containerBox")
            .field("x0", &containerBbox::x0)
            .field("y0", &containerBbox::y0)
            .field("z0", &containerBbox::z0)
            .field("x1", &containerBbox::x1)
            .field("y1", &containerBbox::y1)
            .field("z1", &containerBbox::z1)
            ;

function("createBbox", &createBbox);
}

我收到以下编译错误:

error: C++ requires a type specifier for all declarations function("createBbox", &createBbox);

不要介意 Point6f 和 containerBbox 定义之间的冗余,那些是无关紧要的,我什至没有设法让 emscripten 页面的示例工作(参见:https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#value-types),所以我不确定可能是什么问题。

类似于value_obj需要命名空间,需要在function前面加上emscripten::。否则,编译器会认为您在声明一个名为 function 的 C++ 函数时没有给它一个 return 类型。