conda-forge / geant4-feedstock

A conda-smithy repository for geant4.
BSD 3-Clause "New" or "Revised" License
8 stars 10 forks source link

cmake+geant4 can't find EXPAT library in Mac OS X #28

Open wgseligman opened 3 years ago

wgseligman commented 3 years ago

Issue:

I'm having problems compiling a program within conda that uses Geant4. I can reproduce the issue as follows:

Within conda, I created a geant4 environment on both Linux CentOS 7 and Mac OS X Mojave:

conda create -y --name geant4 cmake geant4

Then I try to build any of the examples using cmake:

cd $CONDA_PREFIX/share/Geant4-10.7.2/examples/basic/
mkdir B1-build
cd B1-build
cmake ../B1

In Linux, this builds without a problem. But in Mac OS, cmake has a problem finding the EXPAT library. Here is the output:

``` cmake ../B1 -- The C compiler identification is AppleClang 11.0.0.11000033 -- The CXX compiler identification is AppleClang 11.0.0.11000033 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done CMake Error at /Users/seligman/opt/anaconda3/envs/geant4/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find EXPAT: Found unsuitable version "2.0.1", but required is at least "2.2.5" (found /Users/seligman/opt/anaconda3/envs/grams-devel/lib/libexpat.dylib) Call Stack (most recent call first): /Users/seligman/opt/anaconda3/envs/geant4/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:592 (_FPHSA_FAILURE_MESSAGE) /Users/seligman/opt/anaconda3/envs/geant4/share/cmake-3.21/Modules/FindEXPAT.cmake:65 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) /Users/seligman/opt/anaconda3/envs/geant4/share/cmake-3.21/Modules/CMakeFindDependencyMacro.cmake:47 (find_package) /Users/seligman/opt/anaconda3/envs/geant4/lib/Geant4-10.7.2/Geant4Config.cmake:281 (find_dependency) CMakeLists.txt:16 (find_package) ```

As you can see in the details below, conda installed expat-2.4.1 as part of the geant4 installation. When I look at the library /Users/seligman/opt/anaconda3/envs/grams-devel/lib/libexpat.dylib, I see it contains the string expat_2.4.1.

Why is it that, using conda-forge-supplied cmake, expat, and geant4, and after finding a library that apparently is of the appropriate version, that cmake is reporting this error? And why only on Mac OS and not CentOS?


Environment (conda list):

``` $ conda list # packages in environment at /Users/seligman/opt/anaconda3/envs/geant4: # # Name Version Build Channel boost 1.74.0 py39ha641261_3 conda-forge boost-cpp 1.74.0 hff03dee_4 conda-forge bzip2 1.0.8 h0d85af4_4 conda-forge c-ares 1.17.2 h0d85af4_0 conda-forge ca-certificates 2021.5.30 h033912b_0 conda-forge clhep 2.4.4.0 h046ec9c_0 conda-forge cmake 3.21.2 hdbd2f3e_0 conda-forge expat 2.4.1 he49afe7_0 conda-forge freetype 2.10.4 h4cff582_1 conda-forge geant4 10.7.2 py39h20ade89_0 conda-forge geant4-data-abla 3.1 0 conda-forge geant4-data-emlow 7.13 0 conda-forge geant4-data-ensdfstate 2.3 hd8ed1ab_0 conda-forge geant4-data-incl 1.0 0 conda-forge geant4-data-ndl 4.6 0 conda-forge geant4-data-particlexs 3.1.1 hd8ed1ab_0 conda-forge geant4-data-photonevaporation 5.7 hd8ed1ab_0 conda-forge geant4-data-pii 1.3 1 conda-forge geant4-data-radioactivedecay 5.6 hd8ed1ab_0 conda-forge geant4-data-realsurface 2.2 hd8ed1ab_0 conda-forge geant4-data-saiddata 2.0 0 conda-forge icu 68.1 h74dc148_0 conda-forge jpeg 9d hbcb3906_0 conda-forge krb5 1.19.2 hcfbf3a7_0 conda-forge libblas 3.9.0 11_osx64_openblas conda-forge libcblas 3.9.0 11_osx64_openblas conda-forge libclang 11.1.0 default_he082bbe_1 conda-forge libcurl 7.79.0 hf45b732_0 conda-forge libcxx 12.0.1 habf9029_0 conda-forge libedit 3.1.20191231 h0678c8f_2 conda-forge libev 4.33 haf1e3a3_1 conda-forge libffi 3.4.2 he49afe7_2 conda-forge libgfortran 5.0.0 9_3_0_h6c81a4c_23 conda-forge libgfortran5 9.3.0 h6c81a4c_23 conda-forge liblapack 3.9.0 11_osx64_openblas conda-forge libllvm11 11.1.0 hd011deb_2 conda-forge libnghttp2 1.43.0 h07e645a_0 conda-forge libopenblas 0.3.17 openmp_h3351f45_1 conda-forge libpng 1.6.37 h7cec526_2 conda-forge libpq 13.3 hea3049e_0 conda-forge libssh2 1.10.0 h52ee1ee_0 conda-forge libuv 1.42.0 h0d85af4_0 conda-forge libxcb 1.13 h35c211d_1003 conda-forge llvm-openmp 12.0.1 hda6cdc1_1 conda-forge lz4-c 1.9.3 he49afe7_1 conda-forge mysql-common 8.0.25 h694c41f_2 conda-forge mysql-libs 8.0.25 h115446f_2 conda-forge ncurses 6.2 h2e338ed_4 conda-forge nspr 4.30 hcd9eead_0 conda-forge nss 3.69 h31e2bf1_0 conda-forge numpy 1.21.2 py39h7eed0ac_0 conda-forge openssl 1.1.1l h0d85af4_0 conda-forge pip 21.2.4 pyhd8ed1ab_0 conda-forge pthread-stubs 0.4 hc929b4f_1001 conda-forge python 3.9.7 h1248fe1_1_cpython conda-forge python_abi 3.9 2_cp39 conda-forge qt 5.12.9 h126340a_4 conda-forge readline 8.1 h05e3726_0 conda-forge rhash 1.4.1 h35c211d_0 conda-forge setuptools 58.0.4 py39h6e9494a_1 conda-forge sqlite 3.36.0 h23a322b_1 conda-forge tk 8.6.11 h5dbffcc_1 conda-forge tzdata 2021a he74cb21_1 conda-forge wheel 0.37.0 pyhd8ed1ab_1 conda-forge xerces-c 3.2.3 h379762d_2 conda-forge xorg-kbproto 1.0.7 h35c211d_1002 conda-forge xorg-libice 1.0.10 h0d85af4_0 conda-forge xorg-libsm 1.2.3 h0d85af4_1000 conda-forge xorg-libx11 1.7.2 h0d85af4_0 conda-forge xorg-libxau 1.0.9 h35c211d_0 conda-forge xorg-libxdmcp 1.1.3 h35c211d_0 conda-forge xorg-libxext 1.3.4 h0d85af4_1 conda-forge xorg-libxmu 1.1.3 h0d85af4_0 conda-forge xorg-libxt 1.2.1 h0d85af4_2 conda-forge xorg-xextproto 7.3.0 h35c211d_1002 conda-forge xorg-xproto 7.0.31 h35c211d_1007 conda-forge xz 5.2.5 haf1e3a3_1 conda-forge zlib 1.2.11 h7795811_1010 conda-forge zstd 1.5.0 h582d3a0_0 conda-forge ```


Details about conda and system ( conda info ):

``` $ conda info active environment : geant4 active env location : /Users/seligman/opt/anaconda3/envs/geant4 shell level : 1 user config file : /Users/seligman/.condarc populated config files : /Users/seligman/.condarc conda version : 4.10.3 conda-build version : 3.21.4 python version : 3.8.8.final.0 virtual packages : __osx=10.14.6=0 __unix=0=0 __archspec=1=x86_64 base environment : /Users/seligman/opt/anaconda3 (writable) conda av data dir : /Users/seligman/opt/anaconda3/etc/conda conda av metadata url : None channel URLs : https://conda.anaconda.org/conda-forge/osx-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/osx-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/osx-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /Users/seligman/opt/anaconda3/pkgs /Users/seligman/.conda/pkgs envs directories : /Users/seligman/opt/anaconda3/envs /Users/seligman/.conda/envs platform : osx-64 user-agent : conda/4.10.3 requests/2.25.1 CPython/3.8.8 Darwin/18.7.0 OSX/10.14.6 UID:GID : 501:20 netrc file : None offline mode : False ```
wgseligman commented 3 years ago

I found the answer to my problem, which only raised more issues.

In my searches for the cause of the problem, I looked in the CMakeCache.txt file. I found the line:

EXPAT_INCLUDE_DIR:PATH=/Library/Frameworks/Mono.framework/Headers

When I used

strings /Library/Frameworks/Mono.framework/Versions/1.9.1/lib/libexpat.dylib | grep expat

I saw that indeed that library had EXPAT version 2.0.1.

I never installed Mono explicitly on my computer. It must have been installed as part of some older package; the files are dated from 2013. I took the risk that nothing I'm using today still uses Mono and did:

sudo rm -rf /Library/Frameworks/Mono.framework

Now the cmake process runs through to completion.

Now the question becomes: Why did the EXPAT package search process find an obscure library header path instead of the one included in the conda environment?

HealthyPear commented 1 year ago

I have the same problem which propagates to zlib.

My expat path that cmake found is

/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include

and (a too old) ZLIB is found at

/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include

even though I tell CMake to not use it (aka -DGEANT4_USE_SYSTEM_ZLIB=OFF)

because I also have that in my conda environment (I had to install it my self)

expat 2.5.0 hf0c8a7f_0 conda-forge libzlib 1.2.13 hfd90126_4 conda-forge zlib 1.2.13 hfd90126_4 conda-forge

HealthyPear commented 1 year ago

Ups! I forgot that I did this sometime ago and I followed this recipe https://github.com/conda-forge/geant4-feedstock/issues/4#issuecomment-696571469

Though this makes me think: just installing Geant4 doesn't appear to be enough...should the recipe include the installation of those packages by default @chrisburr ?

By creating the environment with geant4 + cmake + compilers (make is not necessary) the build of the example works out-of-the-box.

tkittel commented 1 year ago

I am not sure if it is relevant, but a few months ago I noticed that for proper operation I had to explicitly add expat to my conda .yml file in addition to geant4, before our Geant4-based code would work correctly on both linux and mac (I don't recall the details of what was wrong when I didn't). Perhaps it would help to add expat also in the run: section of https://github.com/conda-forge/geant4-feedstock/blob/main/recipe/meta.yaml ?