2015-10-26 46 views
1

我使用mex命令來構建包含在sfun.c我的C代碼:傳遞字符串參數Matlab的MEX命令

mex CFLAGS="\$CFLAGS -std=gnu99" sfun.c; 

可正常工作。但是,我想以編程方式更改部分CFLAGS="\$CFLAGS -std=gnu99"。我想這部分分配給一個變量,並把它傳遞給mex命令緊隨其後,但它失敗:

bv = 'CFLAGS="\$CFLAGS -std=gnu99"' 
mex bv sfun.c 

Matlab的返回此錯誤:

gcc: error: bv: No such file or directory 

mex: compile of ' "sfun.c"' failed. 

什麼是用程序生成bv最接近的方式並將該值傳遞給mex命令?

+0

如果您找到解決方案,我會很感激它,如果你分享它。 – Ian

回答

-1

你想

mex(bv, 'sfun.c'); 

一般來說,

foo bar baz 

被視爲同

foo('bar', 'baz') 

所以你的命令傳遞文字串 'BV' 到墨西哥。

+0

這不起作用。在R2017a嘗試了這個建議和一些變化,但沒有取得成功。 – Ian

+0

@Ian,我不確定你有什麼麻煩,但是這確實有效。 '>> disp(version)' 9.2.0.556344(R2017a) '>> bv ='CFLAGS =「\ $ CFLAGS -std = gnu99」'; mex(bv,'sfun.c')' 建立'gcc'。 墨西哥成功完成。 '>> sfun' Hello world – SCFrench

+0

https://stackoverflow.com/questions/48668913/how-to-pass-filepath-variables-to-mex-command那是我們解決問題的地方。我再次嘗試過你沒有成功,所以我不知道。 – Ian