Hello, thanks for answering and sorry for not giving enough details, I'll try to explain it better.
Then I have taken an example from MATLAB that compiles and works perfectly when using mex with Microsoft Visual 2017 c++ compiler (the compiler needed for chai3d).
Then I copy that example (called "prueba.cpp") in the folder where the chai3d libraries are downloaded:
Finally, I just add a line including the chai3d.h file: #include "chai3d.h". Here is where the problems come. When I try compiling after adding that line, MATLAB returns an error saying that chai3d.h cannot be found. This is solved changing the include sentence into #include "src/chai3d.h" as long as it is the right path. I do not really understand why I have to specify the full path when I added every folder to MATLAB paths.
When compiling with "src/chai3d.h", it returns another error that says that in one of the files of the library it cannot be found some files and this happens over and over when fixing the previous errors.
Thanks for answering so fast and I hope you can help me.
Example:
#include "mexAdapter.hpp"
using namespace matlab::data;
using matlab::mex::ArgumentList;
class MexFunction : public matlab::mex::Function {
void operator()(ArgumentList outputs, ArgumentList inputs) {
checkArguments(outputs, inputs);
const double offSet = inputs[0][0];
TypedArray<double> doubleArray = std::move(inputs[1]);
for (auto& elem : doubleArray) {
outputs[0] = doubleArray;
void checkArguments(ArgumentList outputs, ArgumentList inputs) {
std::shared_ptr<matlab::engine::MATLABEngine> matlabPtr = getEngine();
// Check first input argument
if (inputs[0].getType() != ArrayType::DOUBLE ||
inputs[0].getType() == ArrayType::COMPLEX_DOUBLE ||
inputs[0].getNumberOfElements() != 1)
matlabPtr->feval(u"error",
std::vector<Array>({ factory.createScalar("First input must scalar double") }));
// Check second input argument
if (inputs[1].getType() != ArrayType::DOUBLE ||
inputs[1].getType() == ArrayType::COMPLEX_DOUBLE)
matlabPtr->feval(u"error",
std::vector<Array>({ factory.createScalar("Input must double array") }));
// Check number of outputs
if (outputs.size() > 1) {
matlabPtr->feval(u"error",
std::vector<Array>({ factory.createScalar("Only one output is returned") }));