2929
3030%% MexTask
3131bindir = fullfile(plan .RootFolder , pkg_name );
32- [compiler_id , compiler_opt ] = get_compiler_options();
32+ [compiler_id , compiler_opt , linker_opt ] = get_compiler_options();
3333
3434if isMATLABReleaseOlderThan(" R2024b" )
3535 % dummy task to allow "buildtool mex" to build all MEX targets
4646 mex_name = " mex_" + name ;
4747 % specifying .Inputs and .Outputs enables incremental builds
4848 % https://www.mathworks.com/help/matlab/matlab_prog/improve-performance-with-incremental-builds.html
49- plan(mex_name ) = matlab .buildtool .Task(Actions = @(context ) legacyMexTask(context , compiler_id , compiler_opt ));
49+ plan(mex_name ) = matlab .buildtool .Task(Actions = @(context ) legacyMexTask(context , compiler_id , compiler_opt , linker_opt ));
5050 plan(mex_name ).Inputs = src ;
5151 plan(mex_name ).Outputs = fullfile(bindir , name + " ." + mexext());
5252 mex_deps(end + 1 ) = mex_name ; % #ok<AGROW>
5353 else
5454 plan(" mex:" + name ) = matlab .buildtool .tasks .MexTask(src , bindir , ...
55- Options= [compiler_id , compiler_opt ]);
55+ Options= [compiler_id , compiler_opt , linker_opt ]);
5656 end
5757end
5858
6363end
6464
6565
66- function legacyMexTask(context , compiler_id , compiler_opt )
66+ function legacyMexTask(context , compiler_id , compiler_opt , linker_opt )
6767bindir = fileparts(context .Task .Outputs .Path );
68- mex(context .Task .Inputs .Path , " -outdir" , bindir , compiler_id , compiler_opt )
68+ mex(context .Task .Inputs .Path , " -outdir" , bindir , compiler_id , compiler_opt , linker_opt )
6969end
7070
7171
@@ -130,16 +130,16 @@ function publishTask(context)
130130end
131131
132132
133- function [compiler_id , compiler_opt ] = get_compiler_options()
133+ function [compiler_id , compiler_opt , linker_opt ] = get_compiler_options()
134134
135135cxx = mex .getCompilerConfigurations(' c++' );
136136flags = cxx .Details .CompilerFlags ;
137137
138138msvc = startsWith(cxx .ShortName , " MSVCPP" );
139139
140140std = " -std=c++17" ;
141- compiler_id = " " ;
142-
141+ compiler_id = string . empty ;
142+ linker_opt = string . empty ;
143143if msvc
144144 std = " /std:c++17" ;
145145 % on Windows, Matlab doesn't register unsupported MSVC or oneAPI
@@ -149,17 +149,9 @@ function publishTask(context)
149149 warning(" Xcode Clang++ " + cxx .Version + " may not support this Matlab version" )
150150 end
151151 end
152- elseif isunix && cxx .ShortName == " g++"
153- % FIXME: update when desired GCC != 10 for newer Matlab
154- if isMATLABReleaseOlderThan(" R2025b" ) && ~startsWith(cxx .Version , " 10" )
155- % https://www.mathworks.com/help/matlab/matlab_external/choose-c-or-c-compilers.html
156- % https://www.mathworks.com/help/matlab/matlab_external/change-default-gcc-compiler-on-linux-system.html
157- [s , ~ ] = system(" which g++-10" );
158- if s == 0
159- compiler_id = " CXX=g++-10" ;
160- else
161- warning(" GCC 10 not found. GCC " + cxx .Version + " may fail on runtime" )
162- end
152+ elseif isunix
153+ if cxx .ShortName == " g++" && ~stdlib .version_atleast(cxx .Version , " 9" )
154+ linker_opt = " -lstdc++fs" ;
163155 end
164156end
165157
0 commit comments