Is it possible to mex a .cpp include lots of .h file provide by mathworks.

I want to mex a .cpp file, however, the .cpp file include a .h file (Refer as 1.h) provided by mathworks, 1.h include another .h file (Refer as 2.h) provided by mathworks, as a result, there are lots of .h file from mathworks are included. When call mex, it will return an error due to there is some .h file by mathworks not found. I wonder if it's possible to mex file without find and copy all .h files into one files?

1 commentaire

This happens all the time in the normal course of mexing files. E.g., having
#include "mex.h"
will include that file, and inside that file is this line
#include "matrix.h"
So just doing regular mexing already does what you apparently are having problems with ... it includes an additional file that you didn't explicitly specify.
Can you give more details as to how you are doing your compiling, and what exactly are the includes that you have in your code?

Connectez-vous pour commenter.

Réponses (3)

Walter Roberson
Walter Roberson le 21 Nov 2017
"I wonder if it's possible to mex file without find and copy all .h files into one files"
No.

8 commentaires

Walter Roberson
Walter Roberson le 22 Nov 2017
Modifié(e) : Walter Roberson le 23 Nov 2017
If a #include is conditionally compiled out based upon the defines then there would be no error from mex about the .h not being found.
So, we are dealing with the case where a #include is not conditionally compiled out, and the question is "Is there a compiler setting that will allow compilation to proceed even if an #include asked for by the source is not found?"
Whether any particular compiler supported such an option would be compiler specific. It would be a preprocessor option; the gcc family of compilers for one has no such option; https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options
The only time such an option would be useful is if the missing header file contained definitions for macros or types that are not actually used by any of the source -- the case where the .h file does not actually need to be #include'd . If anything in the .h file is actually used, using such an option would just postpone the error messages, very likely leading to a host of strange errors that would lead you down the wrong path.
The more robust way to deal with missing #include files under the assumption that the #include is not actually used for anything, would be to create an empty version of the missing .h file, and use the -I option (mex, or gcc family) to ad that directory to the include path.
now the question is that i want to invoke mdlInitialize_CAN_datatype(S) as mentioned by mathworks. However, i will always get an error undefined reference to mdlinitialize_CAN_datatype
yes i linked .lib,however,i don't know how to deal with .dll, is there anyway to link the dll during build?
Try copying the dll to the directory you are executing from.
yes,I already implement your suggestion,also the file are copied to the same one fold. still there is the same error. i will share my code soon for your convenient to evaluate.
Please find my code from below link. Thanks.

Connectez-vous pour commenter.

xian zhao
xian zhao le 29 Nov 2017
I get the solution, I mex my code with MinGW before. However it's not compatilbe with .lib generated by microsoft VS. And when I try mex with microsoft visual studio, the mex proceed successfully.

1 commentaire

Hello Xian,
I'm encountering the same error message: "undefined reference to `mdlInitialize_CAN_datatype(SimStruct_tag*)'". Could you please assist me with creating a Mex function using Microsoft Visual Studio?
Thank you for your help

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Compiler dans Centre d'aide et File Exchange

Question posée :

le 21 Nov 2017

Commenté :

le 7 Juin 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!