|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
各位:
最近正在学习使用DPI-C。我有一个C文件,如下:
- #include <svdpi.h>
- #include <math.h>
- double sin(double r){
- return sin(r);
- }
- int sum(int a, int b){
- reurn a+b;
- }
复制代码 然后,在sv中,
- module dpi_test;
- import "DPI-C" function real sin(real n2);
- import "DPI-C" function int sum(int a, int b);
- int a, b, c;
- initial begin
- $display("sin(0.73)=%f", sin(0.73));
- a=2;
- b=7;
- c=sum(a,b);
- $display("a+b=%d", c);
- end
- endmodule
复制代码 我首先是用 vcs 直接编译sv文件和C文件:
- vcs -full64 -sverilog +v2k +cli -kdb -o ./simv -l cmp.log dpi_test.sv c_func.c -debug_all +DPI
复制代码 然后,运行./simv,得到STACK_OVERFLOW的报错:
- Info:[STACK_OVERFLOW] Stack Overflow Detected.
- Note:[STACK_INCREASED] Bumping stack from 8388608 to 18846720 bytes.
- .....
- -- Stack trace follows:
- Dumping VCS Annotated Stack:
- #0 0x00000036916ac89e in waitpid() from /lib64/libc.so.6
- #1 0x000000369163e4e9 in do_system() from /lib64/libc.so.6
- ......
复制代码 然后,如果先用gcc编译C,
- gcc -I$VCS_HOME/nclude -shard -fPIC -o libdpi.so c_func.c -lm
复制代码 然后再用上面的vcs编译命令(去掉c_func.c),再执行./simv
前面的sin计算倒是出来结果了,但是,后面的sum函数,则得到错误提示:
- Error - [DPI-DIFNF] DPI import function not found.
- The definition of DPI import function/task 'sum' does not exist. Please check the started DPI import function/task is defined, and its definition is either passed in a source file at cimpile-time, or provided in a shared library specified using the LRM Annex-J options at run-time.
复制代码 我该怎么做,才能让这两个函数都能正常使用呢?
|
|