类似gcc中的编译过程,可以通过写make.m文件来进行编译:
make.m的写法(在原博主文档中进行了简化):
clear all;
is_64bit = strcmp(computer,'MACI64') || strcmp(computer,'GLNXA64') || strcmp(computer,'PCWIN64');
CPPFLAGS = ' -IE:\opencv\opencv\build\include -IE:\opencv\opencv\build\include\opencv'; % 包含目录,主要-I和路径之间没有空格
LDFLAGS = ' -LE:\opencv\opencv\build\x64\vc14\lib'; %库目录 -L和路径间没有空格
LIBS = ' -lopencv_world310 -lopencv_world310d ';
if is_64bit
CPPFLAGS = [CPPFLAGS ' -largeArrayDims'];%如果是64位则加上,用于提高性能
end
compile_files = {
% the list of your code files which need to be compiled
'RGB2Gray.cpp'%编译的cpp,可以是多个
};
%-------------------------------------------------------------------
%% compiling...
for k = 1 : length(compile_files)
str = compile_files{k};
fprintf('compilation of: %s\n', str);
str = [str CPPFLAGS LDFLAGS LIBS]%拼接成命令
args = regexp(str, '\s+', 'split');%这个必须得加上,按空格分割
mex(args{:});%编译
end
fprintf('Congratulations, compilation successful!!!\n');
原文档路径:https://blog.youkuaiyun.com/zouxy09/article/details/20553007
regexp(str, ‘\s+’, ‘split’);方法的说明路径:https://blog.youkuaiyun.com/gotomic/article/details/7898307