使用emscripten编译结构时出错

Error compiling structures with emscripten

本文关键字:出错 结构 编译 emscripten 使用      更新时间:2023-10-16

我用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);
}

我得到以下编译错误:

错误:C++要求所有声明都使用类型说明符函数("createBbox",&createBbox(;

不要介意Point6f和containerBbox的定义之间的冗余,这些都无关紧要,我甚至没能让emscripten页面的例子发挥作用(请参阅:https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/embind.html#value-类型(,所以我不确定问题出在哪里。

类似于value_obj需要名称空间,您需要将emscripten::放在function前面。否则,编译器会认为您在声明一个名为function的C++函数,而没有给它返回类型。