Hi,
I'm trying to incorporate existing c++ functions into Matlab coder using coder.ceval, but am struggling to even get a basc example working. I've seen the C example here, but am struggling to get even a simple 'hello world working with c++.
I've written a functin 'helloWorld.cpp' as follows:
#include <iostream>#include "helloWorld.h"using namespace std;double helloWorld(double inpt) { cout << "Hello World!!!" << endl; cout << "Input is " << inpt << endl; return inpt;}
And then made 'helloWorld.h' as follows:
#if defined __cplusplusextern "C" {#endif#ifndef HELLOWORLD_H_#define HELLOWORLD_H_double helloWorld(double inpt);#endif /* HELLOWORLD_H_ */#if defined __cplusplus}#endif
My matlab function is then:
function out = helloWorld(inpt)%#codegen
if coder.target('MATLAB') fprintf('Hello World! \n'); fprintf('Input number is %d \n', inpt); out = inpt;else out = 0; source1 = 'helloWorld.cpp'; coder.updateBuildInfo('addSourceFiles',source1); out = coder.ceval('helloWorld',inpt);endend
I tried to compile this using the coder app, calling it as:
inpt = 2.0; out = helloWorld(inpt);
But it fails, with the Target Build Log telling me:
helloWorld1.c: In function ‘helloWorld’:helloWorld1.c:24:3: error: incompatible type for argument 1 of ‘helloWorld’ return helloWorld(inpt); ^helloWorld1.c:18:8: note: expected ‘const struct emlrtStack *’ but argument is of type ‘real_T’ real_T helloWorld(const emlrtStack *sp, real_T inpt) ^helloWorld1.c:24:3: error: too few arguments to function ‘helloWorld’ return helloWorld(inpt); ^helloWorld1.c:18:8: note: declared here real_T helloWorld(const emlrtStack *sp, real_T inpt)
What am I doing wrong here?
Cheers,
Arwel
Best Answer