Clear Filters
Clear Filters

Error generating mex file using CasADi library: undefined reference

16 views (last 30 days)
I want to generate a mex file using the CasADi library.
However, I get an error that <function name> is undefined and cannot be referenced.
The error statement is as follows:
Error using mex
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x18d): undefined reference to `osqp_update_lin_cost'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x212): undefined reference to `osqp_update_bounds'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x299): undefined reference to `osqp_update_P_A'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x3a8): undefined reference to `osqp_warm_start_x'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x3f1): undefined reference to `osqp_warm_start_y'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0x402): undefined reference to `osqp_solve'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0xcfa): undefined reference to
`osqp_set_default_settings'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0xdf6): undefined reference to `osqp_setup'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0xe74): undefined reference to `osqp_cleanup'
C:\Users\n\AppData\Local\Temp\mex_489471697093928_10400\test.obj:test.c:(.text+0xf44): undefined reference to `osqp_cleanup'
collect2.exe: error: ld returned 1 exit status
Error in test (line 31)
mex('-v',ipath,"test.c")
I would appreciate guidance on how to resolve it.
  2 Comments
Koki
Koki on 13 Dec 2023
Sorce code is as follows:
import casadi.*
addpath("C:\MATLABlib\casadi-3.6.4-windows64-matlab2018b")
%% CasADi
% Getting and setting elements in matrices
% Symbols/expressions
% min. 1/2(x'Hx)+g'x
% s.t. Ax <= uba
H = MX.sym('H_val',2,2);
g = MX.sym('g_val',2,1);
A = MX.sym('A_val',3,2);
uba = MX.sym('uba_val',3,1);
qp = struct;
qp.h = H.sparsity();
qp.a = A.sparsity();
% Function Definition
S = conic('S','osqp',qp);
r = S('h', H, 'g', g,'a', A, 'uba', uba);
opts = struct('main',true,...
'mex', true);
S.generate('test.c',opts);
ipath = ['-I' fullfile(pwd,'casadi-3.6.4-windows64-matlab2018b','include')];
mex('-v',ipath,"test.c")

Sign in to comment.

Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!