Skip to content

Commit

Permalink
240217.031538.HKT revise linker_options in compile.m
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang committed Feb 16, 2024
1 parent 9467efd commit 732d367
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ if (PRIMA_HEAP_ARRAYS)
endif ()

# Set additional linker flags
# Zaikun 20230217: Fix https://github.com/libprima/prima/issues/158, which is due to the new linker
# implemented in Xcode 15 on macOS. It happens only if the Fortran compiler is ifort.
# Zaikun 20240217: Fix https://github.com/libprima/prima/issues/158, which is due to the new linker
# implemented in Xcode 15 on macOS. It happens only if the Fortran compiler is ifort.
# An alternative is `add_link_options("-ld_classic")`, which forces Xcode to use the old linker.
# Will CMake adapt itself to the new linker later? Will a newer version of CMake make the fix unnecessary?
# See
Expand Down Expand Up @@ -95,7 +95,7 @@ else()
message(WARNING "No git detected and .git-archival.txt does not contain a version number")
set(PRIMA_VERSION "unknown")
endif()

endif()
# Remove the leading v from PRIMA_VERSION, if it contains one.
string(REGEX REPLACE "^v" "" PRIMA_VERSION ${PRIMA_VERSION})
Expand Down
14 changes: 9 additions & 5 deletions matlab/setup_tools/compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ function compile(solvers, mexdir, fortd, gateways, options)
% https://fortran-lang.discourse.group/t/frecursive-assume-recursion-and-recursion-thread-safety
compiler_configurations = mex.getCompilerConfigurations('fortran', 'selected');
extra_compiler_options = '';
if contains(compiler_configurations.Manufacturer, 'gnu', 'IgnoreCase', true) % gfortran
compiler_manufacturer = lower(compiler_configurations.Manufacturer);
if contains(compiler_manufacturer, 'gnu') % gfortran
extra_compiler_options = '-fno-stack-arrays -frecursive';
elseif contains(compiler_configurations.Manufacturer, 'intel', 'IgnoreCase', true) % Intel compiler
elseif contains(compiler_manufacturer, 'intel') % Intel compiler
if ispc
extra_compiler_options = '/heap-arrays /assume:recursion';
else
extra_compiler_options = '-heap-arrays -assume recursion';
end
elseif ~contains(compiler_configurations.Manufacturer, 'nag', 'IgnoreCase', true) % NAG compiler
elseif ~contains(compiler_manufacturer, 'nag') % NAG compiler
warning('prima:UnrecognizedCompiler', 'Unrecognized compiler %s. The package may not work.', ...
compiler_configurations.Name);
end
Expand All @@ -98,8 +99,11 @@ function compile(solvers, mexdir, fortd, gateways, options)
% 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//g") -undefined dynamic_lookup';
if ismac && contains(compiler_manufacturer, 'intel') % macOS with Intel compiler
[status, ~] = system('type echo && type sed'); % Check if `echo` and `sed` are available.
if status == 0
linker_options = 'LDFLAGSVER="$(echo $LDFLAGSVER | sed "s/-undefined error//g") -undefined dynamic_lookup"';
end
end

% MEX options shared by all compiling processes below.
Expand Down

0 comments on commit 732d367

Please sign in to comment.