Problem with basics of including C++ code with coder (coder.ceval)
Afficher commentaires plus anciens
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 __cplusplus
extern "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);
end
end
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
1 commentaire
Walter Roberson
le 17 Fév 2021
Modifié(e) : Walter Roberson
le 18 Fév 2021
coder.cinclude() might be needed?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Texas Instruments C2000 Processors dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!