How to compile using Legacy Code and gsl library
조회 수: 3 (최근 30일)
이전 댓글 표시
I have gsl library and suscesfully compiled the bessel example using MinGW and msys.
However, when I try to use a C-program that needs the gsl library, the mex compiler seems not to recognize the link.
This is what I am trying to run:
def = legacy_code('initialize'); %Inicialize the definitions
def.SFunctionName = 'new_7'; % Define the name of the S-function
def.OutputFcnSpec = 'eemd_v2(double u1[1], double y1[9][400])'; %Specify outputs
def.HeaderFiles = {'eemd.h'}; %Add libraries
def.SourceFiles = {'eemd.c', 'eemd_v2.c'}; %Add the source file
def.IncPaths = {'gsl'}; %Including the folder gsl in the paths
def.LibPaths = {'C:\MinGW\lib', 'C:\MinGW\include', 'C:\MinGW\include\gsl'};
%Generate and compile your function
legacy_code('sfcn_cmex_generate',def)
legacy_code('compile',def)
The legacy generate the new7.c file but when it tries to compilate, this error message is retrived:
### Start Compiling new_7
mex('-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\gsl', '-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c', '-c', '-outdir', 'C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2', 'C:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\eemd.c')
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
mex('-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\gsl', '-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c', '-c', '-outdir', 'C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2', 'C:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\eemd_v2.c')
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
mex('new_7.c', '-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\gsl', '-IC:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c', 'C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj', 'C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd_v2.obj')
Building with 'MinGW64 Compiler (C)'.
C:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\new_7.c: In function 'mdlOutputs':
C:\Users\ywb18182\Documents\MATLAB\Real-time Matlab\test_EMD_c\new_7.c:157:5: warning: implicit declaration of function 'eemd_v2' [-Wimplicit-function-declaration]
eemd_v2(u1, y1);
^
Error using mex
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1a6): undefined reference to `gsl_rng_alloc'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1e3): undefined reference to `gsl_rng_set'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x21e): undefined reference to `gsl_rng_free'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x76d): undefined reference to `gsl_set_error_handler_off'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x7ee): undefined reference to `gsl_poly_dd_init'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x7fe): undefined reference to `gsl_strerror'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x870): undefined reference to `gsl_poly_dd_eval'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xa68): undefined reference to `gsl_vector_view_array'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xa81): undefined reference to `gsl_vector_view_array'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xa93): undefined reference to `gsl_vector_view_array'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xaa5): undefined reference to `gsl_vector_view_array'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xabf): undefined reference to `gsl_vector_view_array'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xad7): undefined reference to `gsl_linalg_solve_tridiag'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xae2): undefined reference to `gsl_strerror'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0xf63): undefined reference to `gsl_set_error_handler_off'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1032): undefined reference to `gsl_stats_sd'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1191): undefined reference to `gsl_ran_gaussian'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x14ff): undefined reference to `gsl_set_error_handler_off'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1689): undefined reference to `gsl_ran_gaussian'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x1753): undefined reference to `gsl_stats_sd'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.text+0x177e): undefined reference to `gsl_stats_sd'
C:\Users\ywb18182\AppData\Local\Temp\tp430e920c_5186_4e6e_ba88_a8ad902a49f2\eemd.obj:eemd.c:(.rdata$.refptr.gsl_rng_mt19937[.refptr.gsl_rng_mt19937]+0x0):undefined reference to `gsl_rng_mt19937'
collect2.exe: error: ld returned 1 exit status
Error in legacycode.LCT/compile
Error in legacycode.LCT.legacyCodeImpl
Error in legacy_code (line 101)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
>>
I don't know why this is happen because when I try to run the program in the msys it runs normally. I tried to add the options to the compiler but with no sucess:
OPTIONS = {'-I"C:\MinGW\include" -L"C:\MinGW\lib" -lgslcblas -lgsl -lm'};
legacy_code('compile',def,OPTIONS)
My compiler is the 'MinGW64 Compiler (C)'.
What I should do to link the gsl with the MinGW64 Compiler (C) in Matlab?
Thanks
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!