How should I use the specified compiler to compile and generate dynamic libraries when I use codegen in ubuntu

11 次查看(过去 30 天)
I need to use another version of g++ to generate the required library files, which are placed in the /opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin path. What should I do to ensure that I can get the library files that can run on the aarch64 platform after executing the following code:
cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('TargetLibrary', 'none');
inputType = coder.typeof(single(0), [1024, 2, 1]);
codegen -config cfg myNetPredict -args {inputType} -report
PS:Now I run CC = mex.getCompilerConfigurations and CC(1)output as follow:
Name: 'g++'
Manufacturer: 'GNU'
Language: 'C++'
Version: '5.4.0'
Location: '/usr/bin/g++'
ShortName: 'g++'
Priority: 'A'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: '/usr/bin/g++'
LinkerVersion: ''
MexOpt: '/home/test/.matlab/R2024a/mex_C++_glnxa64.xml'

采纳的回答

Adarsh
Adarsh 2025-5-2
Hi @zhi,
I understand that you are trying to generate code in linux x86 aarch64 platform with a compiler other than the default compiler.
If you want to generate a “mexfile, you can follow the below documentation link to change the default compiler:
If you want to generate “libraries/C/C++” code rather than a “mexfile, then you can change the “Toolchain” attribute in the MATLAB Coder configuration parameters as the  toolchain definition provides MATLAB Coder software with information about the software build tools, such as the compiler, linker, archiver.
 MATLAB Coder software uses this information, along with a configuration object or project, to build the generated code. This approach can be used when generating static libraries, dynamic libraries, and executables.
MEX-file generation uses a different approach.
You can use the following command to list all the available toolchains:
coder.make.getToolchains
If you want to use a custom toolchain which is not available in the list then you can register the custom toolchain by following: https://www.mathworks.com/help/coder/custom-toolchain-registration.html
Here is an example code demonstrating on how to modify the Toolchain that is being used by MATLAB Coder:
cfg = coder.config('lib');
cfg.Toolchain = 'GCC Linaro AArch64 Toolchain';
For more information, you can refer to the following documentation links:
  1. https://www.mathworks.com/help/coder/ref/coder.codeconfig.html
  2. https://www.mathworks.com/help/coder/ref/coder.config.html
  3. https://www.mathworks.com/help/coder/ug/what-is-a-custom-toolchain.html
Hope it helps!
  2 个评论
zhi
zhi 2025-5-6
Sorry for replying so late, thank you very much, cfg.Toolchain is very effective. In my case, I need to explicitly set cfg.Toolchain = 'Linaro AArch64 Linux v6.3.1', and set the environment variable export LINARO_TOOLCHAIN_6_3_1_AARCH64=/opt/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin to forcibly replace envVar in the gcc_linaro_aarch64_linux_gnu.m file and point to the actual gcc location. I don't know if this is the right way to do it, but it at least solves my previous problem of not being able to find gcc, but now I can't continue because of the problem that #include <xmmintrin.h> cannot be found. I don't know how to set it so that my compilation process can find the xmmintrin.h header file. I will consult this in other questions
zhi
zhi 2025-5-8
Later supplement: For the problem of missing xmmintrin.h I mentioned, the solution I found is to download the sse2neon header file from https://github.com/DLTcollab/sse2neon/, replace the location containing xmmintrin.h in the MATLAB generated code, first generate the code through codegen -config cfg myNetPredict -args {inputType} -report (there will be an error of missing xmmintrin.h at this time), then modify the code, find the makefile file XX.mk, and directly use makefile -f XX.mk to generate the required lib

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Build Configuration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by