Generate/Link .mexw64 from multiple .obj-files
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthias Frontull
am 20 Feb. 2024
Kommentiert: James Tursa
am 7 Mär. 2024
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 Kommentare
Akzeptierte Antwort
Ayush
am 1 Mär. 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 Kommentare
James Tursa
am 7 Mär. 2024
Note that if your build also includes library files you can just list them in the mex command line as well.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support for MinGW-w64 C/C++ Compiler finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!