gpt4 book ai didi

javascript - 使用 swig 创建 C++ 到 javascript 的包装器时出现构建错误

转载 作者:行者123 更新时间:2023-11-29 22:52:14 25 4
gpt4 key购买 nike

我正在为 swig 中的 javascript 构建一个 c++ 包装器。创建了 example.i 文件编译并创建了 example_wrap.cxx 文件,然后在使用 node-gyp 编译时出现构建错误。

错误:

make: Entering directory '/home/snehabhapkar/Videos/swig/example1/build'
make: *** No rule to make target 'Release/obj.target/example/example.o', needed by 'Release/obj.target/example.node'. Stop.
make: Leaving directory '/home/snehabhapkar/Videos/swig/example1/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:196:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 5.0.9-301.fc30.x86_64
gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "configure" "build"
gyp ERR! cwd /home/snehabhapkar/Videos/swig/example1
gyp ERR! node -v v10.16.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok

请帮忙!谢谢:)

  1. 例子.i
%module example

%inline %{
extern int gcd(int x, int y);
extern double Foo;
%}
  1. 运行以下命令生成 example_wrap.cxx 文件。
swig -javascript -node -c++ example.i
  1. 绑定(bind).gyp
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}
  1. 构建给出上述错误。
node-gyp configure build

最佳答案

我想我在这里看到了问题,虽然我没有可以让我轻松测试它的设置,所以你的 millage 可能会有所不同。

在你的 bindings.gyp 中你有这个:

{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

本质上这就是说您要编译两个 .cxx 文件,一个名为 example.cxx,一个名为 example_wrap.cxx。

构建尝试中的错误消息表明它不知道如何构建“example.o”,这几乎肯定是从“example.cxx”生成的。

我强烈怀疑您的项目中没有名为 example.cxx 的文件。根据您在 SWIG 接口(interface)文件 (example.i) 中编写的内容,您可以避免使用 %inline

基于此,我认为您有两个选择。

  • 首先,您可以从 binding.gyp 文件中删除 example.cxx,并在其中添加包装内容的定义,而不是将它们设为 extern。所以你的 .i 文件变成这样:

    %module example

    %inline %{
    int gcd(int x, int y) {
    // TODO: your code goes here...
    }
    double Foo;
    %}
  • 其次,您可以创建一个 example.cxx 文件。您的 .i 文件保持不变。然后,您需要在该 example.cxx 文件中添加一些代码:

    // implementations of things that SWIG is going to wrap for us go here
    int gcd(int x, int y) {
    // TODO: return some answer here...
    }
    double Foo;

关于javascript - 使用 swig 创建 C++ 到 javascript 的包装器时出现构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57268466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com