Undefined References in CBLAS when testing GSL with CMake - c

I've just installed GSL on my Deepin OS(Linux), and for testing my installation I'm trying to compile a testing file. When compiling with gcc, it works properly, but when using CMake, some Undefined Reference error occurs.
I tried compiling the file main.c with gcc :
gcc main.c -o demo -lm -lgsl -lgslcblas
./demo
and it works properly. But when I tried CMake :
cmake .
make
with a CMakeLists.txt file that looks like :
# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(demo)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(SOURCE_FILES main.c)
add_executable(demo ${SOURCE_FILES})
find_package(GSL REQUIRED)
target_link_libraries(demo GSL::gsl GSL::gslcblas)
such error occurs :
(The output is in Chinese, because of the system language. For example :
/usr/local/lib/libcblas.a(cblas_srotg.o):在函数‘cblas_srotg’中:
cblas_srotg.c:(.text+0x1):对‘srotg_’未定义的引用
means :
/usr/local/lib/libcblas.a(cblas_srotg.o):In function ‘cblas_srotg’ :
cblas_srotg.c:(.text+0x1):Undefined reference to ‘srotg_’.
)
[ 50%] Linking C executable demo
/usr/local/lib/libcblas.a(cblas_srotg.o):在函数‘cblas_srotg’中:
cblas_srotg.c:(.text+0x1):对‘srotg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srotmg.o):在函数‘cblas_srotmg’中:
cblas_srotmg.c:(.text+0x13):对‘srotmg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srot.o):在函数‘cblas_srot’中:
cblas_srot.c:(.text+0x3c):对‘srot_’未定义的引用
/usr/local/lib/libcblas.a(cblas_srotm.o):在函数‘cblas_srotm’中:
cblas_srotm.c:(.text+0x21):对‘srotm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sswap.o):在函数‘cblas_sswap’中:
cblas_sswap.c:(.text+0x21):对‘sswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sscal.o):在函数‘cblas_sscal’中:
cblas_sscal.c:(.text+0x28):对‘sscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_scopy.o):在函数‘cblas_scopy’中:
cblas_scopy.c:(.text+0x21):对‘scopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_saxpy.o):在函数‘cblas_saxpy’中:
cblas_saxpy.c:(.text+0x35):对‘saxpy_’未定义的引用
/usr/local/lib/libcblas.a(sdotsub.o):在函数‘sdotsub_’中:
sdotsub.f:(.text+0x7):对‘sdot_’未定义的引用
/usr/local/lib/libcblas.a(sdsdotsub.o):在函数‘sdsdotsub_’中:
sdsdotsub.f:(.text+0x7):对‘sdsdot_’未定义的引用
/usr/local/lib/libcblas.a(snrm2sub.o):在函数‘snrm2sub_’中:
snrm2sub.f:(.text+0x7):对‘snrm2_’未定义的引用
/usr/local/lib/libcblas.a(sasumsub.o):在函数‘sasumsub_’中:
sasumsub.f:(.text+0x7):对‘sasum_’未定义的引用
/usr/local/lib/libcblas.a(isamaxsub.o):在函数‘isamaxsub_’中:
isamaxsub.f:(.text+0x7):对‘isamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotg.o):在函数‘cblas_drotg’中:
cblas_drotg.c:(.text+0x1):对‘drotg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotmg.o):在函数‘cblas_drotmg’中:
cblas_drotmg.c:(.text+0x13):对‘drotmg_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drot.o):在函数‘cblas_drot’中:
cblas_drot.c:(.text+0x3b):对‘drot_’未定义的引用
/usr/local/lib/libcblas.a(cblas_drotm.o):在函数‘cblas_drotm’中:
cblas_drotm.c:(.text+0x21):对‘drotm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dswap.o):在函数‘cblas_dswap’中:
cblas_dswap.c:(.text+0x21):对‘dswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dscal.o):在函数‘cblas_dscal’中:
cblas_dscal.c:(.text+0x25):对‘dscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dcopy.o):在函数‘cblas_dcopy’中:
cblas_dcopy.c:(.text+0x21):对‘dcopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_daxpy.o):在函数‘cblas_daxpy’中:
cblas_daxpy.c:(.text+0x38):对‘daxpy_’未定义的引用
/usr/local/lib/libcblas.a(ddotsub.o):在函数‘ddotsub_’中:
ddotsub.f:(.text+0x7):对‘ddot_’未定义的引用
/usr/local/lib/libcblas.a(dsdotsub.o):在函数‘dsdotsub_’中:
dsdotsub.f:(.text+0x7):对‘dsdot_’未定义的引用
/usr/local/lib/libcblas.a(dnrm2sub.o):在函数‘dnrm2sub_’中:
dnrm2sub.f:(.text+0x7):对‘dnrm2_’未定义的引用
/usr/local/lib/libcblas.a(dasumsub.o):在函数‘dasumsub_’中:
dasumsub.f:(.text+0x7):对‘dasum_’未定义的引用
/usr/local/lib/libcblas.a(idamaxsub.o):在函数‘idamaxsub_’中:
idamaxsub.f:(.text+0x7):对‘idamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cswap.o):在函数‘cblas_cswap’中:
cblas_cswap.c:(.text+0x21):对‘cswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cscal.o):在函数‘cblas_cscal’中:
cblas_cscal.c:(.text+0x17):对‘cscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csscal.o):在函数‘cblas_csscal’中:
cblas_csscal.c:(.text+0x28):对‘csscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ccopy.o):在函数‘cblas_ccopy’中:
cblas_ccopy.c:(.text+0x21):对‘ccopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_caxpy.o):在函数‘cblas_caxpy’中:
cblas_caxpy.c:(.text+0x21):对‘caxpy_’未定义的引用
/usr/local/lib/libcblas.a(cdotcsub.o):在函数‘cdotcsub_’中:
cdotcsub.f:(.text+0xb):对‘cdotc_’未定义的引用
/usr/local/lib/libcblas.a(cdotusub.o):在函数‘cdotusub_’中:
cdotusub.f:(.text+0xb):对‘cdotu_’未定义的引用
/usr/local/lib/libcblas.a(icamaxsub.o):在函数‘icamaxsub_’中:
icamaxsub.f:(.text+0x7):对‘icamax_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zswap.o):在函数‘cblas_zswap’中:
cblas_zswap.c:(.text+0x21):对‘zswap_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zscal.o):在函数‘cblas_zscal’中:
cblas_zscal.c:(.text+0x17):对‘zscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zdscal.o):在函数‘cblas_zdscal’中:
cblas_zdscal.c:(.text+0x25):对‘zdscal_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zcopy.o):在函数‘cblas_zcopy’中:
cblas_zcopy.c:(.text+0x21):对‘zcopy_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zaxpy.o):在函数‘cblas_zaxpy’中:
cblas_zaxpy.c:(.text+0x21):对‘zaxpy_’未定义的引用
/usr/local/lib/libcblas.a(zdotcsub.o):在函数‘zdotcsub_’中:
zdotcsub.f:(.text+0x7):对‘zdotc_’未定义的引用
/usr/local/lib/libcblas.a(zdotusub.o):在函数‘zdotusub_’中:
zdotusub.f:(.text+0x7):对‘zdotu_’未定义的引用
/usr/local/lib/libcblas.a(dzasumsub.o):在函数‘dzasumsub_’中:
dzasumsub.f:(.text+0x7):对‘dzasum_’未定义的引用
/usr/local/lib/libcblas.a(dznrm2sub.o):在函数‘dznrm2sub_’中:
dznrm2sub.f:(.text+0x7):对‘dznrm2_’未定义的引用
/usr/local/lib/libcblas.a(izamaxsub.o):在函数‘izamaxsub_’中:
izamaxsub.f:(.text+0x7):对‘izamax_’未定义的引用
/usr/local/lib/libcblas.a(scasumsub.o):在函数‘scasumsub_’中:
scasumsub.f:(.text+0x7):对‘scasum_’未定义的引用
/usr/local/lib/libcblas.a(scnrm2sub.o):在函数‘scnrm2sub_’中:
scnrm2sub.f:(.text+0x7):对‘scnrm2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sgemv.o):在函数‘cblas_sgemv’中:
cblas_sgemv.c:(.text+0x124):对‘sgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sger.o):在函数‘cblas_sger’中:
cblas_sger.c:(.text+0xab):对‘sger_’未定义的引用
cblas_sger.c:(.text+0xe3):对‘sger_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssymv.o):在函数‘cblas_ssymv’中:
cblas_ssymv.c:(.text+0xb4):对‘ssymv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr.o):在函数‘cblas_ssyr’中:
cblas_ssyr.c:(.text+0xa8):对‘ssyr_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr2.o):在函数‘cblas_ssyr2’中:
cblas_ssyr2.c:(.text+0xb2):对‘ssyr2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strmv.o):在函数‘cblas_strmv’中:
cblas_strmv.c:(.text+0x141):对‘strmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strsv.o):在函数‘cblas_strsv’中:
cblas_strsv.c:(.text+0x141):对‘strsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dgemv.o):在函数‘cblas_dgemv’中:
cblas_dgemv.c:(.text+0x120):对‘dgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dger.o):在函数‘cblas_dger’中:
cblas_dger.c:(.text+0xb3):对‘dger_’未定义的引用
cblas_dger.c:(.text+0xeb):对‘dger_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsymv.o):在函数‘cblas_dsymv’中:
cblas_dsymv.c:(.text+0xb4):对‘dsymv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr.o):在函数‘cblas_dsyr’中:
cblas_dsyr.c:(.text+0xa6):对‘dsyr_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr2.o):在函数‘cblas_dsyr2’中:
cblas_dsyr2.c:(.text+0xb0):对‘dsyr2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrmv.o):在函数‘cblas_dtrmv’中:
cblas_dtrmv.c:(.text+0x141):对‘dtrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrsv.o):在函数‘cblas_dtrsv’中:
cblas_dtrsv.c:(.text+0x141):对‘dtrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgemv.o):在函数‘cblas_cgemv’中:
cblas_cgemv.c:(.text+0x205):对‘cgemv_’未定义的引用
cblas_cgemv.c:(.text+0x290):对‘cgemv_’未定义的引用
cblas_cgemv.c:(.text+0x36d):对‘cgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_chemv.o):在函数‘cblas_chemv’中:
cblas_chemv.c:(.text+0x219):对‘chemv_’未定义的引用
cblas_chemv.c:(.text+0x2f0):对‘chemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrmv.o):在函数‘cblas_ctrmv’中:
cblas_ctrmv.c:(.text+0x146):对‘ctrmv_’未定义的引用
cblas_ctrmv.c:(.text+0x200):对‘ctrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrsv.o):在函数‘cblas_ctrsv’中:
cblas_ctrsv.c:(.text+0x154):对‘ctrsv_’未定义的引用
cblas_ctrsv.c:(.text+0x210):对‘ctrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgeru.o):在函数‘cblas_cgeru’中:
cblas_cgeru.c:(.text+0xa6):对‘cgeru_’未定义的引用
cblas_cgeru.c:(.text+0xd9):对‘cgeru_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgerc.o):在函数‘cblas_cgerc’中:
cblas_cgerc.c:(.text+0x13d):对‘cgeru_’未定义的引用
cblas_cgerc.c:(.text+0x18f):对‘cgeru_’未定义的引用
cblas_cgerc.c:(.text+0x1ef):对‘cgerc_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher.o):在函数‘cblas_cher’中:
cblas_cher.c:(.text+0x10a):对‘cher_’未定义的引用
cblas_cher.c:(.text+0x1f7):对‘cher_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher2.o):在函数‘cblas_cher2’中:
cblas_cher2.c:(.text+0x17a):对‘cher2_’未定义的引用
cblas_cher2.c:(.text+0x281):对‘cher2_’未定义的引用
cblas_cher2.c:(.text+0x2bc):对‘cher2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgemv.o):在函数‘cblas_zgemv’中:
cblas_zgemv.c:(.text+0x20f):对‘zgemv_’未定义的引用
cblas_zgemv.c:(.text+0x298):对‘zgemv_’未定义的引用
cblas_zgemv.c:(.text+0x37c):对‘zgemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zhemv.o):在函数‘cblas_zhemv’中:
cblas_zhemv.c:(.text+0x219):对‘zhemv_’未定义的引用
cblas_zhemv.c:(.text+0x2f0):对‘zhemv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrmv.o):在函数‘cblas_ztrmv’中:
cblas_ztrmv.c:(.text+0x155):对‘ztrmv_’未定义的引用
cblas_ztrmv.c:(.text+0x210):对‘ztrmv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrsv.o):在函数‘cblas_ztrsv’中:
cblas_ztrsv.c:(.text+0x155):对‘ztrsv_’未定义的引用
cblas_ztrsv.c:(.text+0x210):对‘ztrsv_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgeru.o):在函数‘cblas_zgeru’中:
cblas_zgeru.c:(.text+0xa6):对‘zgeru_’未定义的引用
cblas_zgeru.c:(.text+0xd9):对‘zgeru_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgerc.o):在函数‘cblas_zgerc’中:
cblas_zgerc.c:(.text+0x13e):对‘zgeru_’未定义的引用
cblas_zgerc.c:(.text+0x18f):对‘zgeru_’未定义的引用
cblas_zgerc.c:(.text+0x1ef):对‘zgerc_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher.o):在函数‘cblas_zher’中:
cblas_zher.c:(.text+0x14b):对‘zher_’未定义的引用
cblas_zher.c:(.text+0x1a5):对‘zher_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher2.o):在函数‘cblas_zher2’中:
cblas_zher2.c:(.text+0x17b):对‘zher2_’未定义的引用
cblas_zher2.c:(.text+0x281):对‘zher2_’未定义的引用
cblas_zher2.c:(.text+0x2bc):对‘zher2_’未定义的引用
/usr/local/lib/libcblas.a(cblas_sgemm.o):在函数‘cblas_sgemm’中:
cblas_sgemm.c:(.text+0x10f):对‘sgemm_’未定义的引用
cblas_sgemm.c:(.text+0x1a7):对‘sgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssymm.o):在函数‘cblas_ssymm’中:
cblas_ssymm.c:(.text+0xe8):对‘ssymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyrk.o):在函数‘cblas_ssyrk’中:
cblas_ssyrk.c:(.text+0xd7):对‘ssyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ssyr2k.o):在函数‘cblas_ssyr2k’中:
cblas_ssyr2k.c:(.text+0xe5):对‘ssyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strmm.o):在函数‘cblas_strmm’中:
cblas_strmm.c:(.text+0x12a):对‘strmm_’未定义的引用
cblas_strmm.c:(.text+0x1f0):对‘strmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_strsm.o):在函数‘cblas_strsm’中:
cblas_strsm.c:(.text+0x12a):对‘strsm_’未定义的引用
cblas_strsm.c:(.text+0x1f0):对‘strsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dgemm.o):在函数‘cblas_dgemm’中:
cblas_dgemm.c:(.text+0x10f):对‘dgemm_’未定义的引用
cblas_dgemm.c:(.text+0x1a7):对‘dgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsymm.o):在函数‘cblas_dsymm’中:
cblas_dsymm.c:(.text+0xe8):对‘dsymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyrk.o):在函数‘cblas_dsyrk’中:
cblas_dsyrk.c:(.text+0xd7):对‘dsyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dsyr2k.o):在函数‘cblas_dsyr2k’中:
cblas_dsyr2k.c:(.text+0xe5):对‘dsyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrmm.o):在函数‘cblas_dtrmm’中:
cblas_dtrmm.c:(.text+0x122):对‘dtrmm_’未定义的引用
cblas_dtrmm.c:(.text+0x1e0):对‘dtrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_dtrsm.o):在函数‘cblas_dtrsm’中:
cblas_dtrsm.c:(.text+0x122):对‘dtrsm_’未定义的引用
cblas_dtrsm.c:(.text+0x1e0):对‘dtrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cgemm.o):在函数‘cblas_cgemm’中:
cblas_cgemm.c:(.text+0x105):对‘cgemm_’未定义的引用
cblas_cgemm.c:(.text+0x19d):对‘cgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csymm.o):在函数‘cblas_csymm’中:
cblas_csymm.c:(.text+0xe6):对‘csymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_chemm.o):在函数‘cblas_chemm’中:
cblas_chemm.c:(.text+0xe6):对‘chemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cherk.o):在函数‘cblas_cherk’中:
cblas_cherk.c:(.text+0xd7):对‘cherk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_cher2k.o):在函数‘cblas_cher2k’中:
cblas_cher2k.c:(.text+0x108):对‘cher2k_’未定义的引用
cblas_cher2k.c:(.text+0x185):对‘cher2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrmm.o):在函数‘cblas_ctrmm’中:
cblas_ctrmm.c:(.text+0x118):对‘ctrmm_’未定义的引用
cblas_ctrmm.c:(.text+0x1d6):对‘ctrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ctrsm.o):在函数‘cblas_ctrsm’中:
cblas_ctrsm.c:(.text+0x118):对‘ctrsm_’未定义的引用
cblas_ctrsm.c:(.text+0x1d6):对‘ctrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csyrk.o):在函数‘cblas_csyrk’中:
cblas_csyrk.c:(.text+0xd5):对‘csyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_csyr2k.o):在函数‘cblas_csyr2k’中:
cblas_csyr2k.c:(.text+0xe3):对‘csyr2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zgemm.o):在函数‘cblas_zgemm’中:
cblas_zgemm.c:(.text+0x105):对‘zgemm_’未定义的引用
cblas_zgemm.c:(.text+0x19d):对‘zgemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsymm.o):在函数‘cblas_zsymm’中:
cblas_zsymm.c:(.text+0xe6):对‘zsymm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zhemm.o):在函数‘cblas_zhemm’中:
cblas_zhemm.c:(.text+0xe6):对‘zhemm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zherk.o):在函数‘cblas_zherk’中:
cblas_zherk.c:(.text+0xd7):对‘zherk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zher2k.o):在函数‘cblas_zher2k’中:
cblas_zher2k.c:(.text+0x109):对‘zher2k_’未定义的引用
cblas_zher2k.c:(.text+0x18d):对‘zher2k_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrmm.o):在函数‘cblas_ztrmm’中:
cblas_ztrmm.c:(.text+0x118):对‘ztrmm_’未定义的引用
cblas_ztrmm.c:(.text+0x1d6):对‘ztrmm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_ztrsm.o):在函数‘cblas_ztrsm’中:
cblas_ztrsm.c:(.text+0x118):对‘ztrsm_’未定义的引用
cblas_ztrsm.c:(.text+0x1d6):对‘ztrsm_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsyrk.o):在函数‘cblas_zsyrk’中:
cblas_zsyrk.c:(.text+0xd5):对‘zsyrk_’未定义的引用
/usr/local/lib/libcblas.a(cblas_zsyr2k.o):在函数‘cblas_zsyr2k’中:
cblas_zsyr2k.c:(.text+0xe3):对‘zsyr2k_’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/demo.dir/build.make:96: recipe for target 'demo' failed
make[2]: *** [demo] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/demo.dir/all' failed
make[1]: *** [CMakeFiles/demo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
To determine how is the problem brought up, I also tried reproducing the error message with gcc. When compiling with this command :
$ gcc main.c -o demo -lm -lgsl -lcblas -lblas
it works well. When trying :
$ gcc main.c -o demo -lm -lgsl -lcblas # Ignoring BLAS library.
The error message is reproduced. So I guess the problem occurs when linking the BLAS library.
Here is the file main.c
// main.c
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main(void) {
double x = 5.0;
double y;
y = gsl_sf_bessel_J0(x);
printf("J0(%.4lf) = %.4le\n", x, y);
return 0;
}
The expected outcome would be :
J0(5.0000) = -1.7760e-01

Add the following to your CMakeList.txt
find_package(BLAS REQUIRED)

Related

A C language ffmpeg project organized with CMakeLists, encounters errors in the Windows MinGW64 environment

Project Structure
ffmpeg-tutorial
include
libavcodec
libavdevice
libavfilter
libavformat
libavutil
libswresample
libswscale
lib
pkgconfig
libavcodec.a
libavdevice.a
libavfilter.a
libformat.a
libavutil.a
libswresample.a
libswscale.a
CMakeLists.txt
main.c
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(ffmpeg_tutorial)
set(CMAKE_C_STANDARD 11)
include_directories(include)
link_directories(lib)
add_executable(ffmpeg_tutorial main.cpp)
target_link_libraries(ffmpeg_tutorial
avformat
avcodec
avutil
swscale
swresample
z
bz2
iconv
ws2_32
schannel
kernel32
advapi32
kernel32
user32
gdi32
winspool
shell32
ole32
oleaut32
uuid
comdlg32
advapi32
)
main.c
#include <stdio.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
int main() {
std::cout << "Hello, World!" << std::endl;
std::cout << av_version_info() << std::endl;
printf("ffmpeg version is %s\n", av_version_info());
// Open input file
AVFormatContext *inputContext = nullptr;
if (avformat_open_input(&inputContext, "input.mp3", nullptr, nullptr) != 0) {
printf("Couldn't open input file\n");
return -1;
}
// Read input stream
if (avformat_find_stream_info(inputContext, nullptr) < 0) {
printf("Couldn't find stream information\n");
return -1;
}
// Get audio stream index
int audioStream = -1;
for (int i = 0; i < inputContext->nb_streams; i++) {
if (inputContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
audioStream = i;
break;
}
}
if (audioStream == -1) {
printf("Couldn't find audio stream\n");
return -1;
}
}
IDE
clion
ERRORS
[ 50%] Building CXX object CMakeFiles/ffmpeg_tutorial.dir/main.cpp.obj
[100%] Linking CXX executable ffmpeg_tutorial.exe
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavformat.a(tls_schannel.o): in function `tls_write':
D:\Msys64\usr\src\ffmpeg/libavformat/tls_schannel.c:563: undefined reference to `EncryptMessage'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavformat.a(tls_schannel.o): in function `tls_read':
D:\Msys64\usr\src\ffmpeg/libavformat/tls_schannel.c:441: undefined reference to `DecryptMessage'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavcodec.a(mfenc.o):mfenc.c:(.rdata$.refptr.IID_ICodecAPI[.refptr.IID_ICodecAPI]+0x0): undefined reference to `IID_ICodecAPI'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavcodec.a(tiff.o): in function `tiff_uncompress_lzma':
D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:577: undefined reference to `lzma_stream_decoder'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:582: undefined reference to `lzma_code'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavcodec/tiff.c:583: undefined reference to `lzma_end'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: G:/cywen_private/cpp_projects/ffmpeg-tutorial/lib/libavutil.a(random_seed.o): in function `av_get_random_seed':
D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:127: undefined reference to `BCryptOpenAlgorithmProvider'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:130: undefined reference to `BCryptGenRandom'
D:/Msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\Msys64\usr\src\ffmpeg/libavutil/random_seed.c:131: undefined reference to `BCryptCloseAlgorithmProvider'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\ffmpeg_tutorial.dir\build.make:95: ffmpeg_tutorial.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/ffmpeg_tutorial.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/ffmpeg_tutorial.dir/rule] Error 2
mingw32-make: *** [Makefile:123: ffmpeg_tutorial] Error 2
What is the way I compile ffmpeg
downlaod msys2
install mingw64
pacman -S mingw-w64-x86_64-toolchain
install make,diffutils,nasm,yasm,pkg-config
pacman -S base-devl yasm nasm pkg-config
download ffmpeg 5.1
compile
cd ffmpeg
./configure --disable-shared --enable-static --arch=x86_64 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --pkg-config-flags=--static --prefix=../ffmpeg-build
make -j $(nproc)
make install
Project Repoistory
https://github.com/joinwen/learn_ffmpeg.git
Expectation
How to solve errors
In CMakeLists target_link_libraries's parameters is too much, Can I make it short
some advices on the project

Linux RT-Unable to link .lib to VSCode-Undefined reference to `DAQmxCreateTask'

I was trying to cross compile a C code with CMake inside Linux RT using VSCode. But I am encountering an error due to the mistake in linking (.so) file with project. I have gone through many solutions but failed to run the task. My code is given below:
#include<stdio.h>
#include"/home/admin/helloworld/src/NIDAQmx.h"
TaskHandle taskHandle=0;
int ret=0;
void main()
{
printf("Hello world");
ret=DAQmxCreateTask("task",&taskHandle);
printf("Return for creating task is %d\n",ret);
DAQmxStopTask (taskHandle);
DAQmxClearTask(taskHandle);
printf("Task closed ");
}
Error while running the task.
[ 50%] Linking C executable bin/helloWorld
CMakeFiles/helloWorld.dir/home/admin/helloworld/src/helloWorld.c.o:
In function `main':/home/admin/helloworld/src/helloWorld.c:11: undefined reference to `DAQmxCreateTask'
/home/admin/helloworld/src/helloWorld.c:13: undefined reference to `DAQmxStopTask'
/home/admin/helloworld/src/helloWorld.c:14: undefined reference to `DAQmxClearTask'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/helloWorld.dir/build.make:95: bin/helloWorld] Error 1
make[1]: *** [CMakeFiles/Makefile2:68:CMakeFiles/helloWorld.dir/all] Error 2
* The terminal process
"/bin/bash '-c', 'make'" failed to launch
(exit code: 2).
* Terminal will be reused by tasks, press any key to close it.
I modified my CMakeLists.txt as follows:
cmake_minimum_required(VERSION 3.7.2)
# project settings
project(helloWorld VERSION 0.1.0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
set(CMAKE_GENERATOR "Unix Makefiles")
# executable settings
add_executable(helloWorld ../src/helloWorld.c)
set(CMAKE_BUILD_TYPE Debug)
LINK_LIBRARIES(NIDAQmx ../src/libnidaqmx.so)
If I remove the elements associated with NIDAQmx code working properly.

Can't link with libLLVMSupport.a

I'm trying to compile reduced clang "driver.cpp" - added printf for arguments - and i'm getting linking with libLLVMSupport.a error - no StringSaver class found.
# lib
echo "compiling cmd builder (x86_64) ..."
clang++ `../llvm_34_local_installed2/bin/llvm-config --cxxflags` -I ../llvm_34/tools/clang/include -I ../llvm_34_build_local2/tools/clang/include -c ./lib_cmd_builder.cpp -o ./lib_cmd_builder_x86_64.o
echo "linking cmd builder (x86_64) ..."
CMD="clang++ `../llvm_34_local_installed2/bin/llvm-config --ldflags` ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 `../llvm_34_local_installed2/bin/llvm-config --libs` -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule"
echo "[${CMD}]"
${CMD}
Error message:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::StringSaver", referenced from:
typeinfo for (anonymous namespace)::StringSetSaver in lib_cmd_builder_x86_64.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Checking libLLVM is found and contains CommandLine object data:
(found on -L path):
find ../llvm_34_local_installed2/lib/ -name "*upport*"
../llvm_34_local_installed2/lib//libLLVMSupport.a
(contains CommandLine.cpp object data):
ar -t ../llvm_34_local_installed2/lib//libLLVMSupport.a | grep CommandLine
CommandLine.cpp.o
The class StringSaver is declared in CommandLine.cpp:
/Users/asmirnov/Documents/dev/src/llvm_34/include/llvm/Support/CommandLine.h
class StringSaver {
virtual void anchor();
public:
virtual const char *SaveString(const char *Str) = 0;
virtual ~StringSaver() {}; // Pacify -Wnon-virtual-dtor.
};
StringSaver inheritor is declared and implemented in self file (lib_cmd_builder.cpp):
namespace {
class StringSetSaver : public llvm::cl::StringSaver {
public:
StringSetSaver(std::set<std::string> &Storage) : Storage(Storage) {}
const char *SaveString(const char *Str) LLVM_OVERRIDE {
return SaveStringInSet(Storage, Str);
}
private:
std::set<std::string> &Storage;
};
}
i've also checked llvm-config output and it seems to be ok (contain -L and -lLLVMSupport):
clang++ -L/Users/asmirnov/Documents/dev/src/llvm_34_local_installed2/lib -lcurses -lpthread -lz ./lib_cmd_builder_x86_64.o -o exe_cmd_builder_x86_64 -lLLVMInstrumentation -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfo -lLLVMOption -lLLVMLTO -lLLVMLinker -lLLVMipo -lLLVMVectorize -lLLVMBitWriter -lLLVMBitReader -lLLVMTableGen -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo -lLLVMXCoreAsmPrinter -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc -lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcInfo -lLLVMR600CodeGen -lLLVMR600Desc -lLLVMR600Info -lLLVMR600AsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo -lLLVMMipsAsmPrinter -lLLVMHexagonCodeGen -lLLVMHexagonAsmPrinter -lLLVMHexagonDesc -lLLVMHexagonInfo -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info -lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangAnalysis -lclangApplyReplacements -lclangBasic -lclangCodeGen -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangIndex -lclangLex -lclangParse -lclangQuery -lclangRewriteCore -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTidy -lclangTidyGoogleModule -lclangTidyLLVMModule
Also checked it's build for x86_64 (my host device):
lipo -info ../llvm_34_local_installed2/lib/libLLVMSupport.a
input file ../llvm_34_local_installed2/lib/libLLVMSupport.a is not a fat file
Non-fat file: ../llvm_34_local_installed2/lib/libLLVMSupport.a is architecture: x86_64
I had to use -fno-rtti while compiling library sources

"Undefined reference to" no idea why?

Im working on a project for stm32f4 to my school. Im using CooCox IDE.
I wanted to add new files "przerwania.c" and "przerwania.h" to write some functions there - not in "main.c". But I have no idea why CooCox is showing me errors.
Earlier I wanted to move some of functions from main.c to pwm.c and them work! But I would like to make a new files couse i have more functions.
Errors in CooCox look like this:
[mkdir] Created dir: D:\CooCox\CoIDE\workspace\testowy2\testowy2\Debug\obj
[cc] 12 total files to be compiled.
[cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -c -DSTM32F407VG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -ID:\CooCox\CoIDE\workspace\testowy2 -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_boot -ID:\CooCox\CoIDE -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\include -ID:\CooCox\CoIDE\workspace\testowy2\cmsis -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_lib -ID:\CooCox\CoIDE\workspace D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_syscfg.c D:\CooCox\CoIDE\workspace\testowy2\pwm.c D:\CooCox\CoIDE\workspace\testowy2\dupa.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_boot\startup\startup_stm32f4xx.c D:\CooCox\CoIDE\workspace\testowy2\main.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_rcc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_adc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_gpio.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_boot\system_stm32f4xx.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_exti.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\misc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_tim.c
[cc] Starting link
[cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -Wl,-Map=testowy2.map -O0 -Wl,--gc-sections -LD:\CooCox\CoIDE\configuration\ProgramData\testowy2 -Wl,-TD:\CooCox\CoIDE\configuration\ProgramData\testowy2/arm-gcc-link.ld -g -o testowy2.elf ..\obj\stm32f4xx_syscfg.o ..\obj\pwm.o ..\obj\dupa.o ..\obj\startup_stm32f4xx.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\stm32f4xx_exti.o ..\obj\misc.o ..\obj\stm32f4xx_tim.o
[cc] ..\obj\main.o: In function `main':
[cc] D:\CooCox\CoIDE\workspace\testowy2/main.c:336: undefined reference to `Nowafunkcja'
[cc] collect2.exe: error: ld returned 1 exit status
main.c is quite long becouse i have some definitions of few long functions there, so I paste here only a part
#include "stm32f4xx.h"
#include "misc.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_adc.h"
#include "stm32f4xx_exti.h"
#include "przerwania.h"//here is the problem
#include "pwm.h"
int main(void)
{
SystemInit();
//IniDiody();
//TimConfig();
//NVIC_Config();
//IniDiodyPWM();
LEDInit();
EXTILine0_Config();
PWM2();//wiwo
GPIO();//wiwo
Nowafunkcja();//PROBLEM
RCC_Konfiguracja_Adc12();
GPIO_Configuration_Adc1();
ADC1_Configuration();
GPIO_Configuration_Adc1();
GPIO_Configuration_Adc2();
ADC2_Configuration();
IniDiody(GPIO_Pin_14);
IniTimerPrzerwanie1();
while(1)
{
ADC_SoftwareStartConv(ADC1);
ADC_SoftwareStartConv(ADC2);
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
wynikADC1 = (float)ADC_GetConversionValue(ADC1);
while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);
wynikADC2 = (float)ADC_GetConversionValue(ADC2);
wartosc = (int)(wynikADC2 * 15);
//doPWM=(((float)ADCResult) / 41);
//wartosc = (int) doPWM;
//TIM2->CCR3 = (int) doPWM;
TIM3->CCR2 = 65535;
TIM3->CCR1 = wartosc;//(int)(wynikADC2 * 15);
wartoscPrescalera=(int)SystemCoreClock;
}
}
and files:
przerwania.h
#ifndef __przerwaniah
#define __przerwaniah
void Nowafunkcja(void);
#endif
przerwania.c
#include "przerwania.h"
void Nowafunkcja(void)
{
//nothing here - just for test
}
Do you have any idea what is the problem? I'm thinking about this since yesterday and its wird :/
I'll appreciate your help!
Take a look at the line under [cc] 12 total files to be compiled.
When you added pwm.c, you also informed the compiler to include this file. You'll see it listed there. przerwania.c is not.
If you add przerwania the same way you added pwm, your IDE will take care of making sure it is included in the build.
I'm not sure what your current file/folder structure looks like:
http://www.coocox.org/CoIDE/Project_management_config.html can help you determine how to pull those new files into the build.
FWIW:
The (anthropomorphized) compiler step says: Is this valid code? So it looks though your main.c, sees that you included przerwania.h, and comes to the conclusion that you correctly used the Nowafunkcja function (just matched the signature). Even though at this point, it has NOT looked into przerwania.c to find out what it does. The compiler goes on to do this for all of your files and keeps track of what functions are defined in each file. Note that it never found the definition Nowafunkcja, because the compiler never compiled przerwania.c. It did however find the declaration in the .h (because main.c told it exactly where to find the .h)
The linker then gets this stuff from the compiler, including what functions have been defined in all your .c files. That's the first point where something tries to answer the question "Now what code do I actually need to run when he asked me to Nowafunkcja()?". So that's the first point in the build when the tools realized, I never found code for Nowafunkcja in any of the .c files I was looking in.
So, I think that roughly answers "Why", but we need to know more about your project organization to give you a "fix" to make it work.

undefined reference to `main' in C

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
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;
}
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
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
while running this command give below error:
building library run.so
ld: /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 value
collect2: ld returned 1 exit status
make: * [/home/ss69/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so] Error 1
ncsc_run: *E,TBBLDF: Failed to build test library
/home/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so
irun: *E,CCERR: Error during cc compilation (status 1), exiting.
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
I get this error:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../lib64/crt1.o: In function _start':
(.text+0x20): undefined reference tomain'
collect2: ld returned 1 exit status
Exactly how are you using the function void fftw(double FFT_in[],int size) from your comments it sounds like you are coding routine that is called as DLL or as part of a static library.
If this is the case then adding main() isn't going to help, at all.
What you have written is ABSOLUTELY 100% OK, if it is to be used as a callable routine.
What you might need to do is compile this routine into a library, even a static lib. is probably ok. If this is the case then consult your GCC documentation on how to create a static or dynamic lib.
Finally, I have written Verilog code myself, so you can also provide any lines or references to Verilog documentation that you have read and whose instructions you are following. I assume that at some point you are invoking Verilog and supplying it with a list of libraries it can/should use. Your lib should be included in that list.
Am including comments from jxh per his request:
To import the function into SystemVerilog, you need to compile your function into a shared object. Then, you would point SystemVerilog at the shared object. (I don't use SystemVerilog, but that is what I gather from its web page.)
gcc -shared -fPIC -g -Wall -Werror \
-I/home/ss69/fftw/local/include -L/home/ss69/fftw/local/lib \
fftw_test_DPI.c -lfftw3 -lm -o libfftw_test_DPI.so
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
If you cannot get past the first gcc stage then your issue is clearly on the C side.
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)
You have no main function. Every binary must define main. If it doesn't, you don't have a null region of memory that _start defines in the binary, which means your program can't start!
Add a function:
int main(){
fftw(doubleArgumentsArray, intArgument); //Or whatever function calls this function
return 1; //Needed for C89, C99 will automatically return 1
}
Have found the following tutorial on Dynamic Programming Interface (DPI) :
http://www.doulos.com/knowhow/sysverilog/tutorial/dpi/
Specifically, scroll down to the "Including Foreign Language Code".
It should help with background information about how to construct a C modules for SystemVerilog.
Also, the tutorial has the following import statement:
import "DPI" function void slave_write(input int address, input int data);
This SystemVerilog statement obviously has input defs on the parameters, is this required? Your import does NOT identify input vs. output??
I believe this is an issue with some gcc linkers. I added the following linker flag:
irun ... -Wld,-B/usr/lib/x86_64-linux-gnu
And it fixed the issue.

Resources