Generate/Link .mexw64 from multiple .obj-files
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Ayush
2024-3-1
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 个评论
James Tursa
2024-3-7
Note that if your build also includes library files you can just list them in the mex command line as well.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!