Skip to content

Commit 6448d29

Browse files
committed
buildfile: Linux GCC < 9 <filesystem> link flag
Don't use LDFLAGS as it doesn't work--feed the flag to mex directly
1 parent 2be92fb commit 6448d29

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

buildfile.m

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
%% MexTask
3131
bindir = fullfile(plan.RootFolder, pkg_name);
32-
[compiler_id, compiler_opt] = get_compiler_options();
32+
[compiler_id, compiler_opt, linker_opt] = get_compiler_options();
3333

3434
if isMATLABReleaseOlderThan("R2024b")
3535
% dummy task to allow "buildtool mex" to build all MEX targets
@@ -46,13 +46,13 @@
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
5757
end
5858

@@ -63,9 +63,9 @@
6363
end
6464

6565

66-
function legacyMexTask(context, compiler_id, compiler_opt)
66+
function legacyMexTask(context, compiler_id, compiler_opt, linker_opt)
6767
bindir = 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)
6969
end
7070

7171

@@ -130,16 +130,16 @@ function publishTask(context)
130130
end
131131

132132

133-
function [compiler_id, compiler_opt] = get_compiler_options()
133+
function [compiler_id, compiler_opt, linker_opt] = get_compiler_options()
134134

135135
cxx = mex.getCompilerConfigurations('c++');
136136
flags = cxx.Details.CompilerFlags;
137137

138138
msvc = startsWith(cxx.ShortName, "MSVCPP");
139139

140140
std = "-std=c++17";
141-
compiler_id = "";
142-
141+
compiler_id = string.empty;
142+
linker_opt = string.empty;
143143
if 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
164156
end
165157

0 commit comments

Comments
 (0)