- Change directory to fieldtrip, delete all Mex files in the
src/
directory - Edit
src/ft_getopt.c
and replace anymxErrMsgTxt
tomexErrMsgTxt
(notice the 'mex' instead of 'mx') - Rename
mxSerialize.c
tomxSerialize.cpp
(same formxDeserialize
) - Edit those files, and replace the prototype declarations to:
// MX_API_VER has unfortunately not changed between R2013b and R2014a,
// so we use the new MATRIX_DLL_EXPORT_SYM as an ugly hack instead
#if defined(__cplusplus) && defined(MATRIX_DLL_EXPORT_SYM)
namespace matrix{ namespace detail{ namespace noninlined{ namespace mx_array_api{
#endif
EXTERN_C mxArray* mxSerialize(mxArray const *);
EXTERN_C mxArray* mxDeserialize(const void *, size_t);
// and so on, for any other MEX C functions that migrated to C++ in R2014a
#if defined(__cplusplus) && defined(MATRIX_DLL_EXPORT_SYM)
}}}}
using namespace matrix::detail::noninlined::mx_array_api;
#endif
(source: http://undocumentedmatlab.com/blog/serializing-deserializing-matlab-data)
- run
ft_compile_mex.m
, you might get warnings/errors in text, but the script should finish executing without error - then replace all Mex files in FieldTrip with the newly compiled ones:
[~,mex_files] = system(['find . -type f -name "*.' mexext '"']);
not_src = cellfun( @isempty, strfind(mex_files,'src/') );
to_replace = mex_files(not_src);
src_files = mex_files(~not_src);
for i = 1:numel(to_replace)
[p,n,e] = fileparts(to_replace{i});
[~,k]=ismember(n,src_files_names);
if k > 0
disp([ fullfile(p,[n e]) ' will be replaced by ' src_files{k} ]);
copyfile(src_files{k},fullfile(p,[n e]));
end
end