在编译命令中设置mex文件的输出目录

Setting the output directory of mex files in the compiler command

我的项目结构如下:

MainFolder:
  >>InitToolbox.m     //Here addpaths are executed
  >>Compile.m         //Here mex compilations calls are made
    AlgorithmsFolder  //MATLAB code
    UtilitiesFolder   //MATLAB code
    MexFolder         // C++ files
       >>test1.cpp
       >>test2.cu

无论何时我 运行(在 compile.m 中或直接在命令行中)以下编译器调用:

mex -v -largeArrayDims ./MexFolder/test1.cpp ./MexFolder/test2.cu

输出test1.mexw64保存在MainFolder中。

是否有任何方法可以修改编译器调用以在文件的原始位置或特定的用户定义位置创建 .mexw64 文件?

您想使用 outdir 选项为 mex

指定输出目录
mex -v -largeArrayDims ./MexFolder/test1.cpp ./MexFolder/test2.cu -outdir output_directory
上面的

"output_directory"可以是你想要的任何路径。

它也可以是一个变量,但这需要您更新调用方式 mex

outputFolder = 'path/to/folder';

mex('-v', '-largeArrayDims', 'MexFolder/test1.cpp', ...
    'MexFolder/test2.cu', '-outputdir', outputFolder);