首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WebAssembly中使用ngspice库

在WebAssembly中使用ngspice库
EN

Stack Overflow用户
提问于 2020-07-22 23:10:40
回答 1查看 257关注 0票数 1

我需要一些帮助,在一个组件(wasm)项目中使用ngspice作为一个库。

我安装了emsdk和最新版本的emcc (1.39.20),并下载了ngspice版本32的源代码。

最令我惊讶的是,我能够通过遵循本指南将ngspice编译成wasm目标。

代码语言:javascript
复制
emconfigure  ./configure --with-ngshared --disable-debug
emmake make

(为了通过在这一行中添加configure来通过检查,我不得不对.out.js a.out.wasm进行了一点修补:)

代码语言:javascript
复制
# The possible output files:
ac_files="a.out a.out.js a.out.wasm conftest.exe conftest a.exe a_out.exe b.out conftest.*"

这产生了一个libngspice.so.0.0.0文件,我试图从C++代码链接到该文件。然而,这在duplicate symbol: main中失败了。因此,libngspice.so.0.0.0似乎包含了一个main函数,如果我正确理解配置脚本的--with-ngshared的用途,这个函数就不应该存在。

因此,我从ngspice的main中手动删除了main.c函数,并使用上述方法进行了重新编程。这一次,我可以成功地完成我自己的项目,链接到ngspice。但是,当我调用ngSpice_Init时,会收到以下运行时错误:

代码语言:javascript
复制
stderr Note: can't find init file.

exception thrown: RuntimeError: unreachable executed,@http://localhost:8001/sim.js line 1802 > WebAssembly.instantiate:wasm-function[67]:0x24e9
@http://localhost:8001/sim.js line 1802 > WebAssembly.instantiate:wasm-function[88]:0x423b
...

最少可重复的步骤:

  1. 如上编译ngspice
  2. 使用em++ -o sim.html sim.cpp lib/libngspice.so编译下面的代码
代码语言:javascript
复制
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "sharedspice.h"

using namespace std;


int recieve_char(char * str, int id, void* p){
    printf("recieved %s\n", str);
}

int recieve_stat(char* status, int id, void* p){
    printf("status: %s\n", status);
}

int ngexit(int status, bool unload, bool exit, int id, void* p){
    printf("exit: %d\n", status);
}

int recieve_data(vecvaluesall* data, int numstructs, int id, void* p){
    printf("data recieved: %f\n", data->vecsa[0]->creal);
}

int recieve_init_data(vecinfoall* data, int id, void* p){
    printf("init data recieved from: %d\n", id);
}

int ngrunning(bool running, int id, void* p){
    if(running){
        printf("ng is running\n");
    }else{
        printf("ng is not running\n");
    }
}


int main(){


    ngSpice_Init(&recieve_char, &recieve_stat, &ngexit,
             &recieve_data, &recieve_init_data, &ngrunning, (void*)NULL);

    char** circarray = (char**)malloc(sizeof(char*) * 7);
    circarray[0] = strdup("test array");
    circarray[1] = strdup("V1 1 0 1");
    circarray[2] = strdup("R1 1 2 1");
    circarray[3] = strdup("C1 2 0 1 ic=0");
    circarray[4] = strdup(".tran 10u 3 uic");
    circarray[5] = strdup(".end");
    circarray[6] = NULL;
    ngSpice_Circ(circarray);

    ngSpice_Command("run");


    return 0;
}

那么谁能帮我正确编译ngspice库使其成为目标呢?

(在有人问我之前,是的,我见过这个问题,但没有多大帮助)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-23 14:00:04

在对ngspice源代码做了几次更改之后,我能够编译库和示例代码。修补程序和如何将ngspice编译为wasm的指南可以找到这里

(导致我的问题中显示的错误的问题是用示例代码,而不是从通过签名应该返回int的函数中返回任何内容。这在wasm中是不能容忍的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63044454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档