awietek / xdiag

C++ library for Exact Diagonalization of quantum many-body systems
https://awietek.github.io/xdiag
Apache License 2.0
20 stars 5 forks source link

Build fails when using Homebrew gcc on M1 macOS #9

Closed Spuriosity1 closed 1 month ago

Spuriosity1 commented 1 month ago

Steps to reproduce

% cmake -S . -B build
-- The CXX compiler identification is GNU 14.1.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/bin/g++-14 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiler ID     : GNU
-- Compiler version: 14.1.0
-- Build type: Release
-- CMAKE_INSTALL_PREFIX is not set
Default value: /usr/local
Will set it to /Users/spuriosity1/gh/xdiag/install
-- --------    BUILDING NORMAL XDIAG LIBRARY   -------------
-- -------- Determining Linear Algebra backend -------------
-- Could NOT find MKL (missing: MKL_LIBRARIES MKL_INCLUDE_DIRS MKL_INTERFACE_LIBRARY MKL_THREAD_LAYER_LIBRARY MKL_CORE_LIBRARY)
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- Found BLAS: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Accelerate.framework
-- Looking for cheev_
-- Looking for cheev_ - found
-- Found LAPACK: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Accelerate.framework;-lm;-ldl
-- Employing Lapack/Blas as linear algebra backend
-- --------  Determining if OpenMP is present  -------------
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Employing OpenMP
-- --------   Determining if HDF5 is present   -------------
-- Found HDF5: hdf5_cpp-shared (found version "1.14.3") found components: CXX
-- Employing HDF5
-- --------         Creating config.hpp        -------------
-- Found Git: /usr/bin/git (found version "2.37.1 (Apple Git-137.1)")
-- Configuring done (1.8s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/spuriosity1/gh/xdiag/build
% cmake --build build
/Users/spuriosity1/gh/xdiag/xdiag/utils/error.cpp:13:13: error: redefinition of 'const char* std::bad_variant_access::what() const'
   13 | const char *std::bad_variant_access::what() const noexcept {
      |             ^~~
In file included from /Users/spuriosity1/gh/xdiag/xdiag/utils/error.cpp:4:
/opt/homebrew/Cellar/gcc/14.1.0_1/include/c++/14/variant:1334:17: note: 'virtual const char* std::bad_variant_access::what() const' previously defined here
 1334 |     const char* what() const noexcept override
      |                 ^~~~

Note that build also fails under Apple clang, but for different reasons.

awietek commented 1 month ago

Thanks for filing the issue. I never tested gcc on MacOS so this is a valuable test. The line that throws the error is a hack to get variants working in old OSX versions and CLANG. Probably this has an easy fix but I'll have to look into it. Also, please use the commit 4891db9 at the moment. The latest commit did some rewriting which broke some stuff.

Spuriosity1 commented 1 month ago

Can confirm that AppleClang 14.0.0.14000029 is happy with the commit you mentioned. I'll try and write a quick hack to satisfy Homebrew GCC.

awietek commented 1 month ago

That would be amazing. Probably in line 11 of error.cpp one should check if one has both apple and clang, and not just apple as is done currently.

awietek commented 1 month ago

Thank you for the pull request. I merged it now. Please let me know if the latest version 2640a8d now compiles on your machine with GCC. If so then let's close this issue.