CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
69 stars 68 forks source link

C-Compiler issue on mac OS Ventura 13.4 #435

Closed DegCo closed 1 year ago

DegCo commented 1 year ago

Dear developers,

I have problems installing CRPropa on my system:

Did you install CRPropa from git or download a release? I installed version 3.2 from from the releases.

Things that I tried before asking for help: I read and followed the installation instructions at https://crpropa.github.io/CRPropa3/ . Before writing this request I also checked previous installation issues at https://github.com/CRPropa/CRPropa3/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Ainstallation+ . However, this did not work. I receive the following output:

CMake Error at /opt/homebrew/Cellar/cmake/3.26.4/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler

"/opt/homebrew/Cellar/llvm@15/15.0.7/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /Users/arturodegiorgi/CRPropa3-3.2/build/CMakeFiles/CMakeScratch/TryCompile-0GqIQw

Run Build Command(s):/opt/homebrew/Cellar/cmake/3.26.4/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_aa931/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_aa931.dir/build.make CMakeFiles/cmTC_aa931.dir/build
Building C object CMakeFiles/cmTC_aa931.dir/testCCompiler.c.o
/opt/homebrew/Cellar/llvm@15/15.0.7/bin/clang   -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/arturodegiorgi/opt/anaconda3/include  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -MD -MT CMakeFiles/cmTC_aa931.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_aa931.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_aa931.dir/testCCompiler.c.o -c /Users/arturodegiorgi/CRPropa3-3.2/build/CMakeFiles/CMakeScratch/TryCompile-0GqIQw/testCCompiler.c
clang-15: error: unsupported argument 'core2' to option '-march='
make[1]: *** [CMakeFiles/cmTC_aa931.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_aa931/fast] Error 2

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:10 (project)

I have tried to use the newest version of llvm, 16.0.6 and the older one 15.0.7 (the output above), but the result does not change. I have followed the instructions for the Mac in the installing section.

CMakeCache.txt

Do you know how this issue could be solved? I have been trying to fix it for quite a while now without much success.

Thank you very much for your time!! :)

rafaelab commented 1 year ago

Hi @DegCo, Try cleaning up the build folder and then: cmake .. [your options] -DCMAKE_CXX_FLAGS='-mcpu=apple-m1' This works for me (Apple M1 + Clang).

DegCo commented 1 year ago

Hi @rafaelab,

Thank you very much, with that the installation went through.

Really useful!

Unfortunately, the installing part (make install) is now the issue. After having arrived to 76%, it shows again a clang error:

clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

Has it ever happened to you?

Thanks again! That was a huge improvement already :)

rafaelab commented 1 year ago

Error during make install is completely new to me, except when there are permission issues (which is not the case). After the first problem , did you try running cmake after completely cleaning up the build/ folder? Sometimes some stuff remains and affects subsequent compilations.

DegCo commented 1 year ago

I think so. More specifically, following the instructions + your suggestion, I used

$ export LLVM_DIR="/opt/homebrew/Cellar/llvm/16.0.6" $ PYTHON_DIR=/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11 $ LLVM_VERSION=16.0.6 $ PYTHON_VERSION=3.11 $ cmake .. -DCMAKE_CXX_FLAGS='-mcpu=apple-m1' -DCMAKE_INSTALL_PREFIX=$CRPROPA_DIR \ -DPYTHON_EXECUTABLE=$PYTHON_DIR/bin/python$PYTHON_VERSION \ -DPYTHON_LIBRARY=$PYTHON_DIR/lib/libpython$PYTHON_VERSION.dylib \ -DPYTHON_INCLUDE_PATH=$PYTHON_DIR/include/python$PYTHON_VERSION \ -DCMAKE_C_COMPILER=$LLVM_DIR/bin/clang \ -DCMAKE_CXX_COMPILER=$LLVM_DIR/bin/clang++ \ -DOpenMP_CXX_FLAGS="-fopenmp -I$LLVM_DIR/lib/clang/$LLVM_VERSION/include" \ -DOpenMP_C_FLAGS="-fopenmp =libomp -I$LLVM_DIR/lib/clang/$LLVM_VERSION/include" \ -DOpenMP_libomp_LIBRARY=$LLVM_DIR/lib/libomp.dylib \ -DCMAKE_SHARED_LINKER_FLAGS="-L$LLVM_DIR/lib -lomp -Wl,-rpath,$LLVM_DIR/lib" \ -DOpenMP_C_LIB_NAMES=libomp \ -DOpenMP_CXX_LIB_NAMES=libomp \ -DNO_TCMALLOC=TRUE

The full error I get is: [ 74%] Building CXX object CMakeFiles/crpropa.dir/src/magneticLens/ParticleMapsContainer.cpp.o clang-16: warning: argument unused during compilation: '-mcpu=apple-m1' [-Wunused-command-line-argument] [ 74%] Linking CXX shared library libcrpropa.dylib ld: library not found for -lgfortran clang-16: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [libcrpropa.dylib] Error 1 make[1]: *** [CMakeFiles/crpropa.dir/all] Error 2 make: *** [all] Error 2

I have a -lgfortran installed. Could it be that some extra path must be specified?

Thanks!

rafaelab commented 1 year ago

Apparently your system is not finding libgfortran, which is a prerequisite for CRPropa. If this is the case, it is not a CRPropa-related error.

The solution would probably be to look for libgfortran.dylib (or libgfortran.a) and add its folder to LD_LIBRARY_PATH. In my case (OSX, with homebrew), I found it with the command:

sudo find /opt -iname 'libgfortran.dylib' | xargs shasum

Maybe yours isn't in opt/ but somewhere else.

DegCo commented 1 year ago

Thank you very much for the comment. After playing a bit around, I found out that some packages were interfering and now the installation goes through well, up to some warnings.

My last concern regards the make test part. I attach here the LogFile. LastTest.log

The majority of them seems to fail. The main element in common for them is the error message C++ exception with description "basic_string" thrown in the test body.. I have asked around, but it seems that it is not a well documented error. Furthermore, python crashes every time I run at the end of the make test command. Have you got any ideas?

I am very sorry about the large number of problems, but I hope they will be useful also to others!

rafaelab commented 1 year ago

What happens when you run python -c "from crpropa import *"? Some tests are known to be failing in OSX, especially those related to galactic lenses. But if you can run everything else and you don't require this feature, it should be fine.

DegCo commented 1 year ago

After playing around, I gave up and used the virtual environment of Python.

Now it can be installed, but three tests fail: "testCore", "testInteraction", "testMagneticLensPythonInterface".

The examples in the tutorial seem to work. I will try to use the code as it is and keep an eye on possible errors.

Thanks a lot!