legacy_code: Build errors because of compilerOptions
Afficher commentaires plus anciens
Hello,
I want to create some trivial s-function with legacy_code.
There are 2 macros (TEST_DEF1 and TEST_DEF2), which I want to put into "compilerOptions". The 2 macros are used in the function TestFnc().
But somehow, the TestFnc() does not see the 2 macros defined in "compilerOptions" before...
MexTest.c:
#include "MexTest.h"
void TestFnc(double *p_u, double *p_y)
{
*p_y = *p_u + 1;
#ifndef TEST_DEF1
#error "undefined: TEST_DEF1"
#endif
#ifndef TEST_DEF2
#error "undefined: TEST_DEF2"
#endif
}
MexTest.h:
#ifndef MEXTEST_H_
#define MEXTEST_H_
void TestFnc(double *p_u, double *p_y);
#endif
legacy_code tool
def = legacy_code('initialize');
def.HeaderFiles = {'MexTest.h'};
def.SourceFiles = {'MexTest.c'};
def.SFunctionName = 'Test_SFunc_gen';
def.OutputFcnSpec = 'void TestFnc(double u1[1], double y1[1])';
%% Compile C-MEX-s-function
legacy_code('sfcn_cmex_generate', def);
legacy_code('generate_for_sim',def);
legacy_code('compile', def, {'-DTEST_DEF1', '-DTEST_DEF2'});
Mex Build Errors:
### Start Compiling Test_SFunc_gen
mex('-IC:\Users\xxxx\Documents\', '-c', '-outdir', 'C:\Users\xxxx\AppData\Local\Temp\tp05e00c12_2732_4dab_a0f8_f30bd05992f8', 'C:\Users\xxxx\Documents\MexTest.c')
Building with 'MinGW64 Compiler (C)'.
Error using mex
C:\Users\xxxx\Documents\MexTest.c: In function 'TestFnc':
C:\Users\xxxx\Documents\MexTest.c:8:10: error: #error "undefined: TEST_DEF1"
#error "undefined: TEST_DEF1"
C:\Users\xxxx\Documents\MexTest.c:12:10: error: #error "undefined: TEST_DEF2"
#error "undefined: TEST_DEF2"
How could I use the "-D" option correctly for my case?
(Matlab version 2021a)
Thank you very much!
Best regards
Tony
Réponse acceptée
Plus de réponses (1)
Tequila Drinks
le 1 Déc 2021
0 votes
Catégories
En savoir plus sur Code Compilation Customization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!