Generate/Link .mexw64 from multiple .obj-files
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
im am trying to generate a mex-file from my c-Code.
My code includes .c Files and .cpp Files, but have to be generated with the gcc compiler, not with the g++ in order to work.
However, if the makefile includes .cpp files, Matlab switches automatically to the g++ compiler.
My idea was now to generate the .obj file individually/manually with the correct compiler and then link them also manually to mex-file.
But I am not sure if this "manual linking" is even possible in Matlab?
Best regards
Matthias
0 commentaires
Réponse acceptée
Ayush
le 1 Mar 2024
Hi Matthais,
Just for your clarification, MATLAB actually uses both the compilers i.e “gcc” and “g++” under the hood for compiling the “.c” files and “.cpp” files respectively. After the object code is created, “gcc” is again used to build the MEX file. You can peer under the hood to see the execution of the “mex” function by using the “-v” flag. Here is a useful documentation that explains the whole process of creating, compiling, and linking MEX files in great detail:
Also, Yes, it is possible to generate the “.obj” file individually with the corresponding compilers and then link them to a MEX-file of your choosing in MATLAB. Please refer to the below MEX command for linking the two object files manually:
mex -output your_mexfile your_c_code.o your_cpp_code.o
Here is the documentation for the “mex” function for some additional information on how to build such files:
Hope it helps!
2 commentaires
James Tursa
le 7 Mar 2024
Note that if your build also includes library files you can just list them in the mex command line as well.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support for MinGW-w64 C/C++ Compiler dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!