问题
recently I moved my Matlab project from windows OS to Mac OS. so my jpeg_read.mexw64 file didn't work anymore and I needed to create a new mexmaci64 file that is compatible with Mac OS. I Downloaded JpegToolbox from here and then installed Libjpeg using:
brew install libjpeg
in Matlab I tried to use mex:
>> mex -setup
MEX configured to use 'Xcode with Clang' for C language compilation.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
MEX configured to use 'Xcode Clang++' for C++ language compilation.
>>
but when I try:
mex -I/usr/local/Cellar/jpeg/9d/include jpeg_read.c -L/usr/local/Cellar/jpeg/9d/lib
Matlab returns the following error:
Building with 'Xcode with Clang'.
/Users/folder/jpeg_toolbox/jpeg_read.c:294:39: warning: incompatible pointer types passing 'int [2]' to parameter of type 'const mwSize *' (aka 'const unsigned long *') [-Wincompatible-pointer-types]
mxtemp = mxCreateCharArray(2,dims);
^~~~
/Applications/Polyspace/R2020a/extern/include/matrix.h:958:91: note: passing argument to parameter 'dims' here
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *mxCreateCharArray(mwSize ndim, const mwSize *dims);
^
1 warning generated.
Error using mex
Undefined symbols for architecture x86_64:
"_jpeg_CreateDecompress", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_destroy_decompress", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_finish_decompress", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_read_coefficients", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_read_header", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_save_markers", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_std_error", referenced from:
_mexFunction in jpeg_read.o
"_jpeg_stdio_src", referenced from:
_mexFunction in jpeg_read.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
now how can I compile the program? Otherwise, does any of you have already got the mexmaci64 I would need?
回答1:
This error typically happens when a MEX-file uses int
instead of mwSize
for the sizes of an array. Only very old MEX-file code still does this.
For these MEX-files, you need to add -compatibleArrayDims
to the mex
command when compiling. It causes the compiler to select the old 32-bit API instead of one of the newer 64-bit ones. This does limit the maximum size of arrays, but only in a way that is consistent with limits at the time the MEX-file was written.
The alternative solution is to rewrite the MEX-file to use a newer API.
来源:https://stackoverflow.com/questions/64786549/matlab-error-compiling-jpeg-read-c-to-create-mexmaci64-file