diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 42a4da87d7..f6d46b4b38 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -2153,3 +2153,5 @@ ODFITS HATFLDGLS FCCU HIMMELBK +LDFLAGSVER +LINKFLAGS diff --git a/matlab/setup_tools/compile.m b/matlab/setup_tools/compile.m index 435730a743..e0788623ed 100644 --- a/matlab/setup_tools/compile.m +++ b/matlab/setup_tools/compile.m @@ -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'; @@ -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})); @@ -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);