How to get Matlab C++ compiler name in my program?

3 vues (au cours des 30 derniers jours)
Hadi Salimi
Hadi Salimi le 23 Fév 2022
Réponse apportée : Rik le 25 Fév 2022
I am developing a C++ application and I need to get the C/C++ compiler name of Matlab (2017b and newer). I have already tried using Matlab Engine C++ API for launching an engine and then running:
mex -setup C++
But this approach is taking a long time to be completed. Is there any better approach to get the C/C++ compiler name of Matlab without launching a Matlab instance (e.g. reading a configuration file, etc.)?

Réponses (1)

Rik
Rik le 25 Fév 2022
If starting Matlab is fine, then this code will get you all the info you need:
details=get_cpp_compiler_info
details =
CompilerConfiguration with properties: Name: 'g++' Manufacturer: 'GNU' Language: 'C++' Version: '8.3.0' Location: '/usr/bin/g++' ShortName: 'g++' Priority: 'A' Details: [1×1 mex.CompilerConfigurationDetails] LinkerName: '/usr/bin/g++' LinkerVersion: '' MexOpt: '/MATLAB/bin/glnxa64/mexopts/g++_glnxa64.xml'
function details=get_cpp_compiler_info
cc=mex.getCompilerConfigurations;
for details=cc(:).'
if strcmp(details.Language,'C++'),return,end
end
error('C++ compiler not found')
end
If that is not an option, you could try reading the xml file in the prefdir:
fn=sprintf('%s%smex_C++_%s.xml',prefdir,filesep,mexext)
fn = '/tmp/matlabpref/mex_C++_mexa64.xml'
Although you should be aware that I could only find this file on Windows.

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by