我试图在Xcode 9.4.1上通过C ++使用MATLAB引擎,但出现错误:“ Apple Mach-O Linker(Id)Error”。我搜索了答案,发现关闭“位码”可能会有所帮助。但是,当我转到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("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
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 continue\n\n");
fgetc(stdin);
return 0 ;
}
答案 0 :(得分:0)
根据屏幕抓取中显示的错误消息和链接命令,它没有链接到MATLAB库。我不知道如何正确设置Xcode。
您能做的最好是遵循MATLAB documentation中的建议,该建议建议如下使用MATLAB中的mex
命令:
mex -v -client engine <filename.cpp>
当然用实际的源文件名替换<filename.cpp>
。首先将目录更改为该源文件的位置,然后将可执行文件放在该文件的旁边。