Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation issues on macOS #3

Closed
mojaveazure opened this issue Dec 16, 2022 · 6 comments
Closed

Compilation issues on macOS #3

mojaveazure opened this issue Dec 16, 2022 · 6 comments

Comments

@mojaveazure
Copy link

BPCells fails to compile on macOS; the error happens in multiple C++ files at

class _LIBCPP_TYPE_VIS path
error: 'path' is unavailable: introduced in macOS 10.15
    std::filesystem::path dir
@bnprks
Copy link
Owner

bnprks commented Dec 17, 2022

BPCells requires a C++17-capable compiler to build, in part to take advantage of the improved portable filesystem APIs introduced in the C++17 standard library. It looks like there's some amount of expanded compiler support I can get through additional compile flags in the configure script, though. And at least I can provide a clear error message in the case of missing C++17 support.

Some quick research indicates that compilers older than about 2018 may not have the feature and not be supportable

Do you know what compiler version you're building with?

@mojaveazure
Copy link
Author

Clang 14, which I believe was released in March 2022
image

@bnprks
Copy link
Owner

bnprks commented Jan 9, 2023

Sorry for the delay here, just catching up on changes coming back from break.

Based on my research, it looks like Apple may just intentionally not be providing support for the C++17 filesystem API in its pre-2019 operating systems, even for versions of Clang that could otherwise support it: https://stackoverflow.com/a/58668083

I can't really fix this on the BPCells side, though once we hit CRAN most Mac users won't need to compile it themselves. As a stopgap measure, I've implemented a clearer error message up-front when an incompatible compiler is detected prior to package installation.

Short of upgrading your computer's OS version to a more recent release, the actual fix on your end would be to use a clang / gcc version not distributed by Apple.

Just to outline those steps for users who are unsure:
[BEGIN EDIT 4/29/2023]
From my own testing, it seems conda is not a great way to install a newer compiler on an old macOS version.

Here is an approach that I used successfully on a 2015 iMac running macOS 12.6.4 Monterey. This should only be necessary if your first install attempt gets the error:

Unable to compile program with C++17 std::filesystem.
Please install a newer compiler version and set CC and CXX in ~/.R/Makevars

Steps I used:

  1. Install homebrew

  2. Install hdf5 and llvm through homebrew: brew install hdf5 llvm (llvm is the project that clang and clang++ are part of)

  3. Use brew info llvm to get the folder where llvm binaries are installed.

    Output from brew info llvm
    bparks@DN52emcl dotfiles % brew info llvm
    ==> llvm: stable 16.0.2 (bottled), HEAD [keg-only]
    Next-gen compiler infrastructure
    https://llvm.org/
    /usr/local/Cellar/llvm/16.0.2 (6,779 files, 1.6GB)
    Poured from bottle using the formulae.brew.sh API on 2023-04-28 at 15:45:24
    From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm.rb
    License: Apache-2.0 with LLVM-exception
    ==> Dependencies
    [I cut off the rest of the output since it's not needed here]
    

    Here we see the main install folder of /usr/local/Cellar/llvm/16.0.2, so we update ~/.R/Makevars to have

  4. Confirm that hdf5 headers are visible in /usr/local/include:

    ls -l /usr/local/include/hdf5.h
    BPCells % ls -l /usr/local/include/hdf5.h
    lrwxr-xr-x   1 bparks  admin  38 Apr 28 15:48 /usr/local/include/hdf5.h -> ../Cellar/hdf5/1.12.2_2/include/hdf5.h
    
  5. Update ~/.R/Makevars to include both the compiler path for clang/clang++ and the include path for the hdf5 libraries

    CC=/usr/local/Cellar/llvm/16.0.2/bin/clang
    CXX=/usr/local/Cellar/llvm/16.0.2/bin/clang++
    CFLAGS=-I/usr/local/include
    CXXFLAGS=-I/usr/local/include
    
  6. Install BPCells using remotes::install_github("bnprks/BPCells")

For some reason I had trouble using the conda hdf5 with this setup, so I'd recommend using homebrew for both the compiler and hdf5 installation, and deactivate any conda environment you have active prior to installation.
[END EDIT 4/29/2023]

Old instructions prior to 4/29/2023 edit
  1. Install clang via conda: conda install -c conda-forge clang EDIT 4/28/2023: I think installing via homebrew might be more robust brew install llvm. Then in the following instructions replace clang-cpp with clang++
  2. Find the paths for conda's clang and clang-cpp by running which clang and which clang-cpp in your conda env
  3. Edit the file ~/.R/Makevars adding the lines CC=[path-to-clang] and CXX=[path-to-clang-cpp] (more info available in this manual)
  4. Try installing the package again, verifying that the compiler commands printed are calling your conda environment's copy of clang or clang-cpp

I'm closing this for now, but feel free to re-open with a comment if this outlined solution doesn't work for you.

@bnprks bnprks closed this as completed Jan 9, 2023
@mojaveazure
Copy link
Author

Cool, thanks!

@Dzhan4
Copy link

Dzhan4 commented Oct 19, 2023

Sorry to re-open this. I'm having a similar issue but running this on an HPC cluster - not Mac - with more limited permissions - aka no homebrew. The environment uses intel/18.0.2 C++ compilers and I tried setting the link to the compilers in ~/.R/Makevars but I still get the same error. Any advice?

@bnprks
Copy link
Owner

bnprks commented Oct 19, 2023

Hi @Dzhan4, if your issue is not on Mac then I'd suggest filing a new issue so we can try to keep these issue threads more focused. From what you've described so far, my suggestion would be to try seeing if your HPC has any non-intel compilers available. I know BPCells should work with gcc >=8.0 (>=9.1 recommended), or clang >= 7.0 (>= 9.0 recommended). Please re-file a new issue covering your problem if you need more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants