繁体   English   中英

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

[英]Apple Mach-O Linker (Id) Error in Xcode 9.4.1

我试图在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 ;
}

错误信息

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

最好的办法是遵循MATLAB文档中的建议,该建议建议如下使用MATLAB中的mex命令:

mex -v -client engine <filename.cpp>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM