MATLAB - 编译 jpeg_read.c 创建 mexmaci64 文件时出错

标签 matlab compilation macos-catalina mex libjpeg

最近我将 Matlab 项目从 Windows 操作系统转移到了 Mac 操作系统。所以我的 jpeg_read.mexw64 文件不再工作,我需要创建一个与 Mac OS 兼容的新 mexmaci64 文件。 我从here下载了JpegToolbox然后使用以下命令安装 Libjpeg:

brew install libjpeg

在 Matlab 中我尝试使用 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.
>> 

但是当我尝试时:

mex -I/usr/local/Cellar/jpeg/9d/include jpeg_read.c -L/usr/local/Cellar/jpeg/9d/lib

Matlab 返回以下错误:

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)
 

现在我该如何编译程序?否则,你们中有人已经获得了我需要的 mexmaci64 吗?

最佳答案

当 MEX 文件使用 int 而不是 mwSize 作为数组大小时,通常会发生此错误。只有非常旧的 MEX 文件代码仍然可以执行此操作。

对于这些MEX文件,您需要在编译时将-兼容ArrayDims添加到mex命令中。它会导致编译器选择旧的 32 位 API,而不是较新的 64 位 API 之一。这确实限制了数组的最大大小,但仅限于与写入 MEX 文件时的限制一致的方式。

替代解决方案是重写 MEX 文件以使用更新的 API。

关于MATLAB - 编译 jpeg_read.c 创建 mexmaci64 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64786549/

相关文章:

performance - Visual Studio 2012 编译速度慢,互联网使用率高

compilation - 找不到mpif.h编译错误?

openssl - 不常见的 Homebrew 错误 : "Unknown command: switch"

java - 为什么 System.getProperty ("java.io.tmpdir") 在 Mac OS X Catalina 10.15 上返回只读目录

python - 该matlab代码对应的matplotlib代码是什么

Matlab数组操作

Matlab oop - 如何检查两个对象是否相等

matlab - 如何在固定 float 的matlab中转换变量

c++ - 使用模板解决了多重定义

java - 我在 Mac (Catalina) 上安装了 Android Studio,keytool 错误 : 'To use the “keytool” command-line tool you need to install a JDK'