2

I am trying to create a MATLAB function from C++ using mex. For the C++ code I am using CLion. Per default in CLion there is a CMakeLists.txt file, which is responsible for all the linking. This works fine when I'm running it directly in CLion, however I can't figure out how to use it for mex:

arrayProduct.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
)

When I run mex in MATLAB it seems as though it doesn't understand the include.

>> 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)

What is the problem here? Thanks a lot!

schajan
  • 59
  • 5
  • According to the **first** error message `xcrun: error: SDK "macosx10.14.1" cannot be located` the problem is unrelated to including your header. Instead, something wrong with your general settings. Have you tried to google for such error message? See e.g. [this](https://stackoverflow.com/questions/39564420/i-get-xcrun-error-sdk-iphonesimulator-cannot-be-located-when-running-the-t) or [that](https://stackoverflow.com/questions/30388636/git-error-sdk-macosx-cannot-be-located) questions. – Tsyvarev Dec 03 '19 at 19:52
  • Thanks a lot for the answer! If I don't include someFunctions.h in arrayProduct.cpp then this message shows up about four times, but finally it works.. Do you think this causes the problem anyway? – schajan Dec 03 '19 at 20:28

0 Answers0