code-saturne / code_saturne

code_saturne public mirror
https://www.code-saturne.org
GNU General Public License v2.0
215 stars 80 forks source link

7.3 does not build on macOS #99

Closed paspro closed 1 year ago

paspro commented 1 year ago

After the change to the makefiles and the introduction of the $ORIGIN parameter for relocatable builds, code_saturne can no longer compile under macOS because the native linker does not support this parameter, even when using the GNU toolchain since the native linker must always be used. The equivalent parameter for the macOS linker is called @loader_path.

paspro commented 1 year ago

A custom solution for this problem is the following:

  1. In file configure.ac set LDRPATH="-Wl,-rpath," because otherwise on macOS this is an empty string.
  2. In files preprocessor/appli/Makefile.am and src/apps/Makefile.am replace the existing term with the following:
# Relocatable installation

if HAVE_RELOCATABLE
  ORIGINRUNPATH = $(LDRPATH)'\@loader_path/../../lib'
  PLUGINRUNPATH_R = $(LDRPATH)'\@loader_path/../../lib/'$(PACKAGE)
else
  PLUGINRUNPATH_N = $(LDRPATH)$(pkglibdir)
endif
paspro commented 1 year ago

On another note, for macOS in file src/base/cs_system_info.c the lines:

#if defined(__linux__)
#include <stdio.h>
#endif

have to be modified so that this include statement is active

#include <stdio.h>

because stdio.h is needed for proper compilation like in Linux.

YvanFournier commented 1 year ago

Hello,

Regarding stdio.h, I'll change it so that it is always included.

For LDRPATH, this is built from an initial ldflags_rpath variable, which should be set is in config/cs_auto_flags.sh to be more consistent (see "default linker flags near the end). Could you confirm that "host_os" appears as "darwin" in for Mac OS so I can add the test ? There are other tests with "darwin*" in the same file.

I'll let you either propose a patch, or I can write one in the newt few days and let you test it, whichever you prefer.

paspro commented 1 year ago

Yes, it is called "darwin".

paspro commented 1 year ago

These modifications fixed the problems and code_saturne now builds correctly on macOS.