问题描述
你好我收到以下错误而使用gcc编译C code
Hi I am getting below error while compiling a c code using gcc
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
我试图导入 FFTW()
进入功能的。这里是我的code
I am trying to import the fftw()
function into SystemVerilog. Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>
void fftw(double FFT_in[],int size)
{
double *IFFT_out;
int i;
fftw_complex *middle;
fftw_plan fft;
fftw_plan ifft;
middle = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size);
IFFT_out = (double *) malloc(size*sizeof(double));
fft = fftw_plan_dft_r2c_1d(size, FFT_in, middle, FFTW_ESTIMATE); //Setup fftw plan for fft (real 1D data)
ifft = fftw_plan_dft_c2r_1d(size, middle, IFFT_out, FFTW_ESTIMATE); //Setup fftw plan for ifft
fftw_execute(fft);
fftw_execute(ifft);
printf("Input: \tFFT_coefficient[i][0] \tFFT_coefficient[i][1] \tRecovered Output:\n");
for(i=0;i<size;i++)
printf("%f\t%f\t\t\t%f\t\t\t%f\n",FFT_in[i],middle[i][0],middle[i][1],IFFT_out[i]/size);
fftw_destroy_plan(fft);
fftw_destroy_plan(ifft);
fftw_free(middle);
free(IFFT_out);
//return IFFT_out;
}
下面是从哪儿我想FFTW调用系统的Verilog code
Here is a system Verilog code from where I am trying to call fftw
module top;
import "DPI-C" function void fftw(real FFT_in[0:11], int size);
real j [0:11];
integer i,size;
real FFT_in [0:11];
initial begin
size = 12;
FFT_in[0] = 0.1;
FFT_in[1] = 0.6;
FFT_in[2] = 0.1;
FFT_in[3] = 0.4;
FFT_in[4] = 0.5;
FFT_in[5] = 0.0;
FFT_in[6] = 0.8;
FFT_in[7] = 0.7;
FFT_in[8] = 0.8;
FFT_in[9] = 0.6;
FFT_in[10] = 0.1;
FFT_in[11] = 0.0;
$display("Entering in SystemVerilog Initial Block\n");
#20
fftw(FFT_in,size);
$display("Printing recovered output from system verilog\n");
//for(i=0;i<size;i++)
//$display("%f\t\n",(j[i])/size);
$display("Exiting from SystemVerilog Initial Block");
#5 $finish;
end
endmodule
下面是一个伊伦命令编译既systemverilg和C文件
Here is an irun command to compile both systemverilg and C files
# Compile the SystemVerilog files
fftw_test.sv
-access +rwc
# Generate a header file called _sv_export.h
-dpiheader _sv_export.h
# Delay compilation of fftw_test.c until after elaboration
#-cpost fftw_test_DPI.c -end
-I/home/fftw/local/include -L/home/ss69/fftw/local/lib fftw_test_DPI.c -lfftw3 -lm
# Redirect output of ncsc_run to a log file called ncsc_run.log
-log_ncsc_run ncsc_run.log
运行此命令,而在下面的错误:
建设图书馆run.so
LD:/home/fftw/local/lib/libfftw3.a(mapflags.o):创建共享目标时,对`.RODATA搬迁R_X86_64_32不能使用;与-fPIC编译
/homefftw/local/lib/libfftw3.a:看不懂的符号:坏值
collect2:劳工处返回1退出状态
令: * 的[/home/ss69/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so]错误1
ncsc_run:* E,TBBLDF:未能建立试题库
/家庭/ DPI /./ INCA_libs / irun.lnx8664.12.20.nc / librun.so
while running this command give below error:building library run.sold: /home/fftw/local/lib/libfftw3.a(mapflags.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC/homefftw/local/lib/libfftw3.a: could not read symbols: Bad valuecollect2: ld returned 1 exit statusmake: * [/home/ss69/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so] Error 1ncsc_run: *E,TBBLDF: Failed to build test library /home/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so
伊伦:* E,CCERR:CC编译(状态1)时出错,退出
irun: *E,CCERR: Error during cc compilation (status 1), exiting.
当我简单地尝试使用gcc下面的命令来编译C:结果
GCC -g -Wall -Werror -I /家庭/ FFTW /本地/包括-L /家庭/ ss69 / FFTW / local / lib目录\\
fftw_test_DPI.c -lfftw3 -lm -o fftw_test_DPI
When I simply try to compile C using gcc with below command:
gcc -g -Wall -Werror -I/home/fftw/local/include -L/home/ss69/fftw/local/lib \ fftw_test_DPI.c -lfftw3 -lm -o fftw_test_DPI
我得到这个错误:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6 /../../../../ lib64目录/ crt1.o:在功能 _start':
主要
(+的.text 0x20的):未定义引用
collect2:劳工处返回1退出状态
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function _start':(.text+0x20): undefined reference to
main'collect2: ld returned 1 exit status
推荐答案
- 您缺少在fftwc.c文件
的#includesvdpi.h
(或者你没有显示它,因为它是在fftwc.h)。这包括需要的DPI。 - 您正在编译DPI库与一个SystemVerilog的模拟器中使用。因此,你不需要
的main()
方法。 - I preFER总是编译SystemVerilog的编译器之外的所有DPI方法。在包括DPI库模拟阶段。我的流程看起来像下面这样:
结果
- Your are missing
#include "svdpi.h"
in the fftwc.c file (or maybe you are not showing it because it is in fftwc.h). This include is needed for DPI. - You are compiling a DPI library to be used with a SystemVerilog simulator. Therefore, you do not need a
main()
method. - I prefer to always compile all DPI methods outside of the SystemVerilog compiler. The include the DPI library to the simulation phase. My flow looks something like the following:
${SVTOOL} -compile -f svfiles.f -dpi_header gen_dpi_header.h
gcc -fPIC -pipe -O2 -c -g \
-I${SVTOOL_PATH}/include -Imy_dpi_dir -I. \
-o fftw_test_DPI.o \
fftw_test_DPI.c
gcc -shared -o libdpi.so \
fftw_test_DPI.o [other object files]
# then call ${SVTOOL} again for simulation with libdpi.so
如果你不能让过去的第一阶段的gcc那么您的问题显然是在C面。
If you cannot get past the first gcc stage then your issue is clearly on the C side.
我没有此刻访问fftw3库。我想知道FFTW你的无效(双FFT_in [],INT大小)
可能被弄错的库函数。尝试将其重命名无效dpi_fftw(双FFT_in [],INT大小)
I do not have access to the fftw3 library at the moment. I'm wondering your void fftw(double FFT_in[],int size)
might be clobbering a library function. Try renaming it void dpi_fftw(double FFT_in[],int size)
这篇关于未定义的引用'主'用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!