필터 지우기
필터 지우기

Compiling with Mex - Can I reference Environment Variables?

조회 수: 4 (최근 30일)
Danny S
Danny S 2011년 9월 7일
댓글: Timothé Boutelier 2017년 3월 23일
I'm attempting to compile a Simulink S-Function with Mex, which #includes some header files that are from another directory on our system. This directory is defined in an environment variable.
Is it possible to reference the environment variable in the mex -I or -L options?
e.g. mex -I$(REF_DIR)/include my_sfunction.c
On Windows, this is tricky as you refer to environment variables using %REF_DIR%, which won't work in Matlab, as % signifies a comment
Do I just have to bite the bullet and put in the full path? Or edit mexopts.bat?

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2011년 9월 7일
Try:
mex -v COMPFLAGS="$COMPFLAGS -I%REF_DIR%/include" my_sfunction.c
I think this command, or a minor variation on it should work.
  댓글 수: 1
Danny S
Danny S 2011년 9월 7일
Sorry, didn't work - the % sign, even inside double quotes is being interpreted as the start of a comment, and the rest of the line is ignored:
>> mex -v COMPFLAGS="$COMPFLAGS -I%REF_DIR%/include" my_sfunction.c
Unmatched double quote: "$COMPFLAGS -I
??? Error using ==> mex
Unable to complete successfully
Thanks for the suggestion, though.

댓글을 달려면 로그인하십시오.


James Tursa
James Tursa 2011년 9월 8일
Have you tried the function version of the mex command? E.g.,
mex('-v','COMPFLAGS="$COMPFLAGS -I%REF_DIR%/include"','my_sfunction.c')
This will force the arguments with embedded spaces to be interpreted by the mex command as single arguments instead of multiple arguments. You might need to make the 'COMPFLAGS=' a separate argument from the "etc" part ... not sure about this.
  댓글 수: 3
James Tursa
James Tursa 2011년 9월 8일
Can you double up the double quotes inside the double quotes? e.g.,
"$COMPFLAGS -I""%REF_DIR%""/include"
Timothé Boutelier
Timothé Boutelier 2017년 3월 23일
use simple quote instead of double quote: mex -v COMPFLAGS='$COMPFLAGS -I%REF_DIR%/include' my_sfunction.c

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by