spex-xray / spex-help

These are the help and manual pages for the SPEX X-ray spectral fitting package.
1 stars 1 forks source link

Compiling from the source code with macOS Ventura (PGPLOT issue) #34

Open jmao2014 opened 1 year ago

jmao2014 commented 1 year ago

Hi Jelle,

I'm trying to compile from the source code (python compile.py) with macOS Ventura. Presently, the main issue is the PGPLOT library (mixing 32-bit FORTRAN object file and 64-bit C object file). The error message is shown below:

[ 5%] Linking Fortran static library libpgplot.a /Library/Developer/CommandLineTools/usr/bin/ranlib: archive member: libpgplot.a(xwdriv.c.o) cputype (16777223) does not match previous archive members cputype (16777228) (all members must match) /Library/Developer/CommandLineTools/usr/bin/ranlib: archive member: libpgplot.a(grdate.c.o) cputype (16777223) does not match previous archive members cputype (16777228) (all members must match)

[A few more lines similar to those shown above]

I can compile PGPLOT on macOS Ventura successfully, but how do I use it by modifying CMakeLists.txt?

Cheers,

Junjie

jdeplaa commented 1 year ago

Hi Junjie,

To help to see where this is going wrong, I would need some more information.

Given the error message, it looks like an architecture mismatch on M1/M2 chips (osx64 versus osx-arm64), so probably the CMakeLists.txt file needs a clear specification of the architecture in the gcc/clang flag.

Until now, I have only compiled SPEX on M1 using a conda environment with the SPEX dependencies included (and not on Ventura yet) to avoid issues with the Apple libraries. Maybe it is time to try again :)

Cheers,

Jelle.

jmao2014 commented 1 year ago

Hi Jelle,

I'm trying to compile SPEX on an Apple Silicon processor (M1 ultra).

I'm compiling with the gfortran-gcc compiler combination.

"I have only compiled SPEX on M1 using a conda environment with the SPEX dependencies included"

Do you have a recipe for that? I can also give it a go.

Cheers,

Junjie

jdeplaa commented 1 year ago

I use conda-build using a meta.yaml file to create the build environment. However, if you create a conda environment with the right dependencies installed, it should work as well. These are the conda packages that I install to build and run SPEX.

The packages between {} are found automatically by conda-build for the specified architecture. It should be possible to install these using conda install as well:

- {{ compiler('fortran') }} -> installs gfortran through conda
- {{ cdt('libx11-devel') }} -> libx11-devel
- {{ cdt('libxau-devel') }} -> libxau-devel
- {{ cdt('libxcb') }} -> libxcb
- {{ cdt('libxext-devel') }} -> libxext-devel
- {{ cdt('xorg-x11-proto-devel') }} -> xorg-x11-proto-devel
- {{ cdt('libpng-devel') }} -> libpng-devel
- spex-cfitsio>=4.2.0
- python
- numpy
- cmake 
- libopenblas
- nomkl
- pthread-stubs
- readline 

Note that cfitsio version 4.2.0 or later is necessary on Apple M1. In this version most of the bugs are fixed.

Once you have a conda enviroment with the packages above, it should be possible to run the commands below:

cmake . -DPYTHON=3 -DPGPLOT=YES -DCMAKE_INSTALL_PREFIX=$PREFIX/opt/spex -DCONDA=YES -DBLA_VENDOR=OpenBLAS -DREADLINE_ROOT_DIR=$CONDA_PREFIX -DCFITSIO_ROOT_DIR=$CONDA_PREFIX/opt/spex
make -j8 
make install 

The above will install SPEX inside the conda environment, but you can change the install location to something else if you want.

Cheers,

Jelle.

jdeplaa commented 1 year ago

I'm compiling with the gfortran-gcc compiler combination.

If you want to continue to try compiling without conda, you could also try to use clang to compile the C routines in PGPLOT:

rm CMakeCache.txt
cmake . -DCMAKE_C_COMPILER=clang -DCMAKE_CPP_COMPILER=clang 

In my previous experience (on MacOS Monterey), both compilers had their troubles on native Mac. This made me try conda to make sure the compiler and the other packages were at least consistently built.