首页 > 解决方案 > 使用 cmake 进行墨西哥

问题描述

我正在尝试使用 mex 从 C++ 创建一个 MATLAB 函数。对于 C++ 代码,我使用的是 CLion。默认情况下,CLion 中有一个 CMakeLists.txt 文件,该文件负责所有链接。当我直接在 CLion 中运行它时,这很好用,但是我不知道如何将它用于 mex:

数组产品.cpp:

#include "mex.h"
#include "someFunctions.h"
void mexFunction(...){
  ...
  printRandomStuff(); // defined in someFunctions.h resp. someFunctions.cpp
  ...
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(mex_attempt)

set(CMAKE_CXX_STANDARD 14)
find_package(Matlab)

matlab_add_mex(
        NAME mex_attempt
        SRC arrayProduct.cpp someFunctions.h someFunctions.cpp
)

当我在 MATLAB 中运行 mex 时,它似乎不理解包含。

>> mex /Users/username/CLionProjects/mex_attempt/arrayProduct.cpp
Error using mex
xcrun: error: SDK "macosx10.14.1" cannot be located
Undefined symbols for architecture x86_64:
  "printRandomStuff()", referenced from:
      _mexFunction in arrayProduct.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这里有什么问题?非常感谢!

标签: c++matlabcmakemex

解决方案


推荐阅读