SV DPI 新手求助
时间:10-02
整理:3721RD
点击:
照着书写的程序, 编译通不过请教哪里有问题?//file: test.sv
import "DPI" function int fact(input int i);
program automatic test;
initial begin
for(int i=1; i<=10; i++)
$display("%0d! = %0d", i, fact(i));
end
endprogram
//file: test.cpp
#include "svdpi.h"
int fact(int i){
if(i<=1) return 1;
elsereturn i*fact(i-1);
}
编译命令:
vcs -sverilog test.sv test.cc -CFLAGS "-I $VCS_HOME/linux/lib"
结果:
Parsing design file 'test.sv'
Top Level Modules:
test
No TimeScale specified
Starting vcs inline pass...
2 modules and 0 UDP read.
recompiling module test
All of 3 modules done
g++ -w-pipe -m32 -I /tool/cbar/apps/vcs/2009.12-3/linux/lib -O -I/tool/cbar/apps/vcs/2009.12-3/include-c ../test.cpp
if [ -x ../simv ]; then chmod -x ../simv; fi
g++-o ../simv -melf_i386 -m32test.o5NrI_d.o 5NrIB_d.o jAci_1_d.o Yrj5_1_d.o gzYz_1_d.o SIM_l.ormapats_mop.o rmapats.o/tool/cbar/apps/vcs/2009.12-3/linux/lib/libvirsim.a /tool/cbar/apps/vcs/2009.12-3/linux/lib/librterrorinf.so /tool/cbar/apps/vcs/2009.12-3/linux/lib/libsnpsmalloc.so/tool/cbar/apps/vcs/2009.12-3/linux/lib/libvcsnew.so/tool/cbar/apps/vcs/2009.12-3/linux/lib/vcs_save_restore_new.o /tool/cbar/apps/vcs/2009.12-3/linux/lib/ctype-stubs_32.a -ldl-lc -lm -lpthread -ldl
gzYz_1_d.o: In function `T_VCSgd_test_1_2_0':
(.text+0x12a): undefined reference to `fact'-------------------------------------------------> look at here!
collect2: ld returned 1 exit status
make: *** [product_timestamp] Error 1
Make exited with status 2
CPU time: .134 seconds to compile + .054 seconds to elab + .523 seconds to link
import "DPI" function int fact(input int i);
program automatic test;
initial begin
for(int i=1; i<=10; i++)
$display("%0d! = %0d", i, fact(i));
end
endprogram
//file: test.cpp
#include "svdpi.h"
int fact(int i){
if(i<=1) return 1;
elsereturn i*fact(i-1);
}
编译命令:
vcs -sverilog test.sv test.cc -CFLAGS "-I $VCS_HOME/linux/lib"
结果:
Parsing design file 'test.sv'
Top Level Modules:
test
No TimeScale specified
Starting vcs inline pass...
2 modules and 0 UDP read.
recompiling module test
All of 3 modules done
g++ -w-pipe -m32 -I /tool/cbar/apps/vcs/2009.12-3/linux/lib -O -I/tool/cbar/apps/vcs/2009.12-3/include-c ../test.cpp
if [ -x ../simv ]; then chmod -x ../simv; fi
g++-o ../simv -melf_i386 -m32test.o5NrI_d.o 5NrIB_d.o jAci_1_d.o Yrj5_1_d.o gzYz_1_d.o SIM_l.ormapats_mop.o rmapats.o/tool/cbar/apps/vcs/2009.12-3/linux/lib/libvirsim.a /tool/cbar/apps/vcs/2009.12-3/linux/lib/librterrorinf.so /tool/cbar/apps/vcs/2009.12-3/linux/lib/libsnpsmalloc.so/tool/cbar/apps/vcs/2009.12-3/linux/lib/libvcsnew.so/tool/cbar/apps/vcs/2009.12-3/linux/lib/vcs_save_restore_new.o /tool/cbar/apps/vcs/2009.12-3/linux/lib/ctype-stubs_32.a -ldl-lc -lm -lpthread -ldl
gzYz_1_d.o: In function `T_VCSgd_test_1_2_0':
(.text+0x12a): undefined reference to `fact'-------------------------------------------------> look at here!
collect2: ld returned 1 exit status
make: *** [product_timestamp] Error 1
Make exited with status 2
CPU time: .134 seconds to compile + .054 seconds to elab + .523 seconds to link
正在学习中。
two options:
[1]chage c code file name from test.cpp to test.c
[2]change test.cpp
extern "C" {
you code ...
}