Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误



我正在尝试通过Xcode 9.4.1上的C++使用MATLAB引擎,但是我收到一个错误:"Apple Mach-O Linker (Id(错误"。我搜索了答案,发现关闭"位码"可能会有所帮助。但是,当我转到Xcode的构建设置时,它就不存在了。我强调,即使您在搜索栏中搜索,它也绝对不存在。如何关闭它,如果不能,我该怎么办?

Undefined symbols for architecture x86_64:
"_engEvalString", referenced from:
_main in main.o
"_engOpen", referenced from:
_main in main.o
"_engPutVariable", referenced from:
_main in main.o
"_mxCreateDoubleMatrix_800", referenced from:
_main in main.o
"_mxGetPr_800", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

以下是完整的代码:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#define  BUFSIZE 256
int main() {
Engine *ep ;
mxArray *Y = NULL, *result = NULL ;
char buffer[BUFSIZE];
double x[10] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
8.0, 9.0};
if (!(ep = engOpen(""))) {
fprintf(stderr, "nCan't start MATLAB enginen");
return EXIT_FAILURE;
}
Y = mxCreateDoubleMatrix(1,10, mxREAL);
memcpy((void *)mxGetPr(Y), (void *)x, sizeof(x));
engPutVariable (ep, "Y", Y) ;
engEvalString(ep, "fx = Y.^2") ;
engEvalString(ep, "plot(Y,fx);");
engEvalString(ep, "f(x) = y^2") ;
engEvalString(ep, "xlabel('x');");
engEvalString(ep, "ylabel('y');");
printf("Hit return to continuenn");
fgetc(stdin);
return 0 ;
}

错误消息

根据屏幕截图中显示的错误消息和链接命令,它没有链接到 MATLAB 库。我不知道如何正确设置 Xcode 来做到这一点。

您能做的最好的事情就是遵循 MATLAB 文档中的建议,该文档建议在 MATLAB 中使用mex命令,如下所示:

mex -v -client engine <filename.cpp>

当然,将<filename.cpp>替换为实际的源文件名。首先将目录更改为该源文件的位置,可执行文件将放在它旁边。

最新更新