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!