Skip to content

Commit

Permalink
Merge pull request libprima#162 from libprima/zaikunzhang-fix-macos-1…
Browse files Browse the repository at this point in the history
…3-mex-failure

Update compile.m to fix libprima#161
  • Loading branch information
zaikunzhang authored Feb 16, 2024
2 parents 6267ab8 + 5e854bb commit 80d7c2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2153,3 +2153,5 @@ ODFITS
HATFLDGLS
FCCU
HIMMELBK
LDFLAGSVER
LINKFLAGS
19 changes: 17 additions & 2 deletions matlab/setup_tools/compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ function compile(solvers, mexdir, fortd, gateways, options)
compiler_options = ['FFLAGS="$FFLAGS ', extra_compiler_options, '"'];
end

% Zaikun 20240216: The following is a workaround for https://github.com/libprima/prima/issues/161,
% where MEX fails due to incompatibility between the new linker of Xcode 15 on macOS and Intel oneAPI 2023.
% The fix is to replace the linker option "-undefined error" with "-undefined dynamic_lookup".
% See also https://github.com/libprima/prima/issues/158.
% Note that we have to modify `LDFLAGSVER`. Setting `LDFLAGS` or `LINKFLAGS` does not work, although
% the latter is suggested at https://www.mathworks.com/help/matlab/ref/mex.html.
linker_options = '';
if ismac && contains(compiler_configurations.Manufacturer, 'intel', 'IgnoreCase', true) % macOS with Intel compiler
linker_options = 'LDFLAGSVER=$(echo $LDFLAGSVER | sed "s/-undefined error/-undefined dynamic_lookup/g")';
end

% MEX options shared by all compiling processes below.
common_mex_options = {verbose_option, compiler_options, linker_options};


% Name of the file that contains the list of Fortran files. There should be such a file in each
% Fortran source code directory, and the list should indicate the dependence among the files.
filelist = 'ffiles.txt';
Expand Down Expand Up @@ -118,7 +133,7 @@ function compile(solvers, mexdir, fortd, gateways, options)

fprintf('Compiling the common files ... ');
for idbg = 1 : length(debug_flags)
mex_options = {verbose_option, ['-', dbgstr(debug_flags{idbg})], compiler_options};
mex_options = [common_mex_options, {['-', dbgstr(debug_flags{idbg})]}];
for iprc = 1 : length(precisions)
prepare_header(header_file, precisions{iprc}, debug_flags{idbg});
work_dir = fullfile(common, pdstr(precisions{iprc}, debug_flags{idbg}));
Expand Down Expand Up @@ -158,7 +173,7 @@ function compile(solvers, mexdir, fortd, gateways, options)
% The support for the classical variant is limited. No debugging version.
continue
end
mex_options = {verbose_option, ['-', dbgstr(debug_flags{idbg})], compiler_options};
mex_options = [common_mex_options, {['-', dbgstr(debug_flags{idbg})]}];
for iprc = 1 : length(precisions)
work_dir = fullfile(soldir, pdstr(precisions{iprc}, debug_flags{idbg}));
prepare_work_dir(work_dir);
Expand Down

0 comments on commit 80d7c2f

Please sign in to comment.