3

EDIT 4 (2023/06/22)

I'm trying to create a PK model using rxode2 package. Unfortunately, I got an error message stating error building model when using rxode({...}) function. Since I'm using a Mac (OS version 12.6.6, Intel processor), I followed the instructions here and here since I saw the message that rxode2 has not detected OpenMP support and will run in single-threaded mode after I loaded the package.

At the end, this is what I did (for reproduction):

  1. Reinstall Xcode Command Line Tools:
sudo rm -rf /Library/Developer/CommandLineTools  
sudo xcode-select --install

However, this results in installing older sdk versions as well. I don't know if this could be related to Xcode that was used in the past. I have reinstalled Xcode but I still have my old projects showing up at Xcode startup and these may have been targeted to previous SDK versions. I'm not sure how to perform a complete removal (not only Xcode but also any settings/configuration files that could be linked to sdk ressources somewhere in my computer).

enter image description here


  1. Check libomp:
brew update && brew install libomp
--> Warning: libomp 16.0.5 is already installed and up-to-date

  1. Update Makevars file:
    Of note (1): I first made a mistake creating this file (a simple txt file using textedit and removing the .txt extention) in my working R directory. I then created it in (what I hope is the good location...) the .r folder located in my $HOME (/Users/username/.r/Makevars)
    Of note (2): R could not locate gfortran. /usr/local/bin/gfortran is a symlink as ls -l /usr/local/bin/gfortran prints /usr/local/bin/gfortran -> ../Cellar/gcc/13.1.0/bin/gfortran. I then modified Makevars accordingly. Currently, the Makevars file looks like this:
LOC=/usr/local/Cellar/gcc/13.1.0
CC=$(LOC)/bin/gcc-13 -fopenmp
CXX=$(LOC)/bin/g++-13 -fopenmp
CXX11=$(LOC)/bin/g++-13 -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/
CPPFLAGS=-I$(LOC)/include -I/usr/local/include

FLIBS=-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/13/gcc/x86_64-apple-darwin21 -L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/ -lgfortran -lquadmath -lm
CXX1X=$(LOC)/bin/g++-13
CXX98=$(LOC)/bin/g++-13
CXX14=$(LOC)/bin/g++-13
CXX17=$(LOC)/bin/g++-13

  1. Install data.table package from source to see if something's going wrong.
    Aside from many warnings (-pedantic flag enabled), I get the following error (as we can see, it uses MacOSX12.sdk even though the last version available is MacOSX13.1.sdk, cf image above):

install.packages("data.table", type = "source")

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64

  1. Reorder $PATH
    As pointed out in this post, the 'tapi file' issue can be caused by the wrong ld command being used when '$HOME/anaconda3/bin/ld' path is preceding '$HOME/usr/bin'.
    Since which -a ld returns Users/username/anaconda3/bin/ld (I have Anaconda activated), I added export PATH=/usr/bin:$PATH at the end of the .bash_profile file in $HOME and then run source ~\.bash_profile into the terminal to have it take effect.

.bash_profile file

export JAVA_HOME=$(/usr/libexec/java_home)

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/username/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/username/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/username/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/username/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

export PATH=/usr/bin:$PATH

And now

$ which -a ld
/usr/bin/ld # it is now preceding $HOME/anaconda3/bin/ld
/Users/username/anaconda3/bin/ld
/usr/bin/ld

But still install.packages("data.table", type = "source") returns

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64

  1. Remove older SDK files
    After removing MacOSX11* and MacOSX12* .sdk files:

enter image description here

install.packages("data.table", type = "source") returns

ld: library not found for -lz

Could it be that the system is looking for MacOSX12.sdk exclusively? After it has been removed, it cannot target the most recent sdk files. MacOSX.sdk and MacOSX13.sdk are symlinks pointing to MacOSX13.1.sdk

ls -l /Library/Developer/CommandLineTools/SDKs/
total 0
lrwxr-xr-x  1 root  wheel   14 15 jui 10:03 MacOSX.sdk -> MacOSX13.1.sdk
drwxr-xr-x  7 root  wheel  224 12 nov  2022 MacOSX13.1.sdk
lrwxr-xr-x  1 root  wheel   14 15 jui 10:02 MacOSX13.sdk -> MacOSX13.1.sdk

I tried to google related issues, and I found this post where it looks like Xcode and SDK versions need to be closely related. Maybe could this problem arise because the MacOS SDK version that is used is MacOSX12 ? Any idea why MacOSX.sdk/MacOSX13.*.sdk cannot be targeted ?


  1. Trying with macrtools
    I installed the development version of macrtools R package from GitHub (as it has superseded the r-macos-rtools installer package). I followed these instructions after removing the Command line tools folder containing all MacOSX* .sdk files:
remotes::install_github("coatless-mac/macrtools")
macrtools::macos_rtools_install()
# Congratulations! 
# Xcode CLI, Gfortran, and R developer binaries have been installed successfully.

But then two new elements come up:
i) In contrast with xcode-select --install, macrtools::macos_rtools_install() only installs MacOSX12 and MacOSX13 sdk files (not MacOSX11).

enter image description here

ii) However:

macrtools::is_xcode_cli_installed()
# FALSE

It says that Xcode CLI is not installed (even though SDK files are now present). The same thing occurs after trying to specifically install Xcode CLI:

macrtools::xcode_cli_install()
# Finding available software
# Downloading Command Line Tools for Xcode
# Downloaded Command Line Tools for Xcode
# Installing Command Line Tools for Xcode
# Done with Command Line Tools for Xcode
# Done.

macrtools::is_xcode_cli_installed()
# FALSE
macrtools::is_gfortran_installed()
# TRUE
macrtools::recipes_binary_install('r-base-dev')
# No error
install.packages("data.table", type = "source")
# ** R
# ** inst
# ** byte-compile and prepare package for lazy loading
# ** help
# *** installing help indices
# ** building package indices
# ** installing vignettes
# ** testing if installed package can be loaded from temporary location
# ** checking absolute paths in shared objects and dynamic libraries
# ** testing if installed package can be loaded from final location
# ** testing if installed package keeps a record of temporary installation path
# * DONE (data.table)

I'm not getting the message error unsupported tapi file type anymore :). But still, OpenMP is not detected:

> library(data.table)
# data.table 1.14.8 using 1 threads (see ?getDTthreads).  Latest news: r-datatable.com
# **********
# This installation of data.table has not detected OpenMP support. It should still work but in single-threaded mode.

  1. Running {rxode2}
    It is now possible to build a PK model without getting an error. However, many similar warnings show up (because of the -pedantic flag in Makevars ?) and I was wondering if they were related to OpenMP non-detection:
ppk_mode = rxode({
  centr(0) = 0;
  TVCl  = THETA_Cl*(CLCREAT/120)^0.8*(0.7^DIAL);
  TVVc  = THETA_Vc*(WT/70)          *(0.5^DIAL);
  TVVp  = THETA_Vp;
  ...
})

# /usr/local/include/stdlib.h:291:20: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
# int      cgetnext(char **, char **);
#                       ^
# /usr/local/include/stdlib.h:291:20: note: insert '_Nullable' if the pointer may be null
# int      cgetnext(char **, char **);
#                       ^
#                        _Nullable
# /usr/local/include/stdlib.h:291:20: note: insert '_Nonnull' if the pointer should never be null
# int      cgetnext(char **, char **);

# And many other similar warnings.

  1. gfortran reinstallation and Makevars update
    After uninstalling and reinstalling gfortran with {macrtools}, it is still located at the same location /usr/local/Cellar/gcc/13.1.0/...
ls -l /usr/local/bin/gfortran
# lrwxr-xr-x  [...] /usr/local/bin/gfortran -> ../Cellar/gcc/13.1.0/bin/gfortran

And

ls /usr/local/gfortran/lib/gcc/
# No such file or directory

Also, running set into the terminal prints x86_64-apple-darwin21 which is different from the platform mentioned by sessionInfo() in R that displays x86_64-apple-darwin20. I'm not sure what {macrtools} did at the end.

This is how the current Makevars file looks like:

LOC=/usr/local/Cellar/gcc/13.1.0
CC=$(LOC)/bin/gcc-13 -fopenmp
CXX=$(LOC)/bin/g++-13 -fopenmp
CXX11=$(LOC)/bin/g++-13 -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/
CPPFLAGS=-I$(LOC)/include -I/usr/local/include

FLIBS=-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/13/gcc/x86_64-apple-darwin21/13 -L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/ -lgfortran -lquadmath -lm
CXX1X=$(LOC)/bin/g++-13
CXX11=/usr/local/gfortran/bin/g++
CXX98=$(LOC)/bin/g++-13
CXX14=$(LOC)/bin/g++-13
CXX17=$(LOC)/bin/g++-13

Unfortunately I get again the tapi error with MacOSX12.sdk that is used:

install.packages("data.table", type = "source")

ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64

I followed the same {macrtools} instructions as before, but I cannot get rid this time of the tapi error message and MacOSX12.sdk issue. During this {macrtools} process, I noticed that it downloaded resources in a darwin20 folder from 'mac.R-project.org' (cf below)

Downloading Command Line Tools for Xcode
Downloaded Command Line Tools for Xcode
Installing Command Line Tools for Xcode
Done with Command Line Tools for Xcode
Done.
gfortran was already installed! ...
Downloading https://mac.R-project.org/bin/REPOS ...
Using repository  https://mac.R-project.org/bin/darwin20/x86_64 ...
Downloading index  https://mac.R-project.org/bin/darwin20/x86_64/PACKAGES ...
Downloading binary:  https://mac.R-project.org/bin/darwin20/x86_64/xz-5.4.2-darwin.20-x86_64.tar.xz ...
trying URL 'https://mac.R-project.org/bin/darwin20/x86_64/xz-5.4.2-darwin.20-x86_64.tar.xz'
Content type 'application/octet-stream' length 559568 bytes (546 KB)
==================================================
downloaded 546 KB

Installing: xz-5.4.2-darwin.20-x86_64.tar.xz into '/opt/R/x86_64' ...
...

For a reason I cannot explain, reproducing the same steps with macrtools results now again in the tapi error. Could it be related to any darwin version discrepancy ?

Of note, I upgraded MacOS to Monterey a few days ago. I reinstalled XQuartz as well. Is there a way to get rid of all these gfortran/gcc, command line tools and SDK-related issues to start from scratch with a clean R / Fortan / SDK / etc. environment ?


  1. Extra information - SessionInfo()

enter image description here

It shows that x86_64-apple-darwin20 platform version is used (and not darwin21 that is installed on my computer and that is the one in Makevars). But changing 21 to 20 in Makevars does not seem to have an influence.


  1. Cleaning and starting again
    Since things look complicated, I uninstalled libomp, lightgbm, llvm, Xcode command line tools and anaconda.
brew uninstall libomp
Error: Refusing to uninstall /usr/local/Cellar/libomp/16.0.5
because it is required by lightgbm, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies libomp
brew uninstall lightgbm
Uninstalling /usr/local/Cellar/lightgbm/3.3.5... (98 files, 18.1MB)
brew uninstall libomp
Uninstalling /usr/local/Cellar/libomp/16.0.5... (7 files, 1.7MB)
brew uninstall llvm
Uninstalling /usr/local/Cellar/llvm/16.0.5... (6,779 files, 1.6GB)

Regarding Anaconda cleaning, I followed instructions here

conda install anaconda-clean
anaconda-clean --yes
Backup directory: /Users/username/.anaconda_backup/2023-06-22T181652
rm -rf ~/anaconda3

I also removed this in ~/.bash_profile

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/username/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /de$
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/username/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/username/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/username/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

Now, bash_profile looks like this:

export JAVA_HOME=$(/usr/libexec/java_home)

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
$PATH
-bash: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin: No such file or directory

However, I noticed that in addition to have anaconda3 files in ~/anaconda3, I also found them in /opt/anaconda3 as mentioned in bash_profile, along with gfortran (among others):

enter image description here

I also found that libomp.dylib is in /opt/anaconda3/lib:

enter image description here

Is this strange or is it something expected ? Should I also remove anaconda3 from this folder ?

which gfortran
# returns nothing, (i.e., expected since /opt is not in $PATH ?)

And lastly,

rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Now, I reinstalled a few things and followed these instructions from here and here:

curl -O https://mac.r-project.org/openmp/openmp-14.0.6-darwin20-Release.tar.gz   # since my Apple clang version is 1400.x   
sudo tar fvxz openmp-14.0.6-darwin20-Release.tar.gz -C /

After unpacking, I indeed find these files:

/usr/local/lib/libomp.dylib
/usr/local/include/ompt.h
/usr/local/include/omp.h
/usr/local/include/omp-tools.h

I added the following lines to $HOME/.R/Makevars that now contains only these lines:

CPPFLAGS += -I/usr/local/include -Xclang -fopenmp
LDFLAGS += -L/usr/local/lib -lomp

As proposed here (item 6), I created and compiled omp_test.c, and then called the compiled C function from R, and got:

OpenMP threads available: 8

  1. Testing with data.table and rxode2
    Aftef being so excited that OpenMP seems to work, I checked with data.table and rxode2 packages
install.packages("data.table", type = "source")
# Many warnings like /usr/local/include/stdlib.h:346:37: note: insert '_Nonnull' if the pointer should never be null
# But installation successful
library(data.table)
# data.table 1.14.8 using 4 threads (see ?getDTthreads).  Latest news: r-datatable.com

Becoming more and more confident, I tried with rxode2. However...

install.packages("rxode2", type = "source")
[...]
using C compiler: ‘Apple clang version 14.0.0 (clang-1400.0.29.202)’
using Fortran compiler: ‘GNU Fortran (GCC) 12.2.0’
using C++ compiler: ‘Apple clang version 14.0.0 (clang-1400.0.29.202)’
**using SDK: ‘MacOSX13.1.sdk’ ----> which was empty previously, this is good news!**

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:642:26: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:642:60: error: no template named 'numeric_limits'
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
                                                           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:643:18: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                 ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:643:50: error: no template named 'numeric_limits'
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
                                                 ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:648:17: error: no template named 'numeric_limits'
  static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
                ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:651:25: error: no template named 'numeric_limits'
  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
                        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:651:58: error: no template named 'numeric_limits'
  return _FloatBigger ? numeric_limits<_IntT>::max() :  (numeric_limits<_IntT>::max() >> _Bits << _Bits);
                                                         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:661:16: error: no template named 'numeric_limits'
  using _Lim = numeric_limits<_IntT>;
               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:664:12: error: use of undeclared identifier '_Lim'
    return _Lim::max();
           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:665:21: error: use of undeclared identifier '_Lim'
  } else if (__r <= _Lim::lowest()) {
                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:666:12: error: use of undeclared identifier '_Lim'
    return _Lim::min();

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cstdlib:138:9: error: target of using declaration conflicts with declaration already in scope
using ::abs _LIBCPP_USING_IF_EXISTS;
        ^
/usr/local/include/stdlib.h:132:6: note: target of using declaration
int      abs(int) __pure2;
         ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: conflicting declaration
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:853:1: error: declaration conflicts with target of using declaration already in scope
abs(const complex<_Tp>& __c)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: target of using declaration
using ::abs _LIBCPP_USING_IF_EXISTS;
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:9: note: using declaration
using ::abs _LIBCPP_USING_IF_EXISTS;
        ^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:910:16: error: reference to unresolved using declaration
        return abs(__c.real());
               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:912:16: error: reference to unresolved using declaration
        return abs(__c.imag());
               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:969:16: error: reference to unresolved using declaration
        __re = abs(__re);
               ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:1022:29: error: reference to unresolved using declaration
    return complex<_Tp>(log(abs(__x)), arg(__x));
                            ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:1049:23: error: reference to unresolved using declaration
    return polar(sqrt(abs(__x)), arg(__x) / _Tp(2));
                      ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
In file included from RcppExports.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25:
In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/RcppCommon.h:65:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/complex:1174:33: error: reference to unresolved using declaration
            return complex<_Tp>(abs(__x.real()), __x.imag());
                                ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:338:1: note: using declaration annotated with 'using_if_exists' here
using ::abs _LIBCPP_USING_IF_EXISTS;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘rxode2’

Unfortunately, there seems to be something missing when trying to install rxode2. Did I forget to reinstall anything ? I also found here some problems related to a wrong value of CMAKE_OSX_SYSROOT and heard about header files to link to usr/local/include. Or even something missing in ~/.R/Makevars ? I really don't know what sould be done next.

Trichophyton
  • 625
  • 5
  • 21
  • Using [these instructions](https://stackoverflow.com/a/65334247/12957340) I am able to compile rxode2 with openMP on macOS 13.4 with an intel processor (`library(rxode2)`: "rxode2 2.0.13 using 2 threads (see ?getRxThreads)"). Based on your warnings/errors, you may need to install a 'fresh' gfortran, either via brew (`brew install gcc`) or from https://github.com/fxcoudert/gfortran-for-macOS/releases – jared_mamrot Jun 05 '23 at 12:11
  • If you can please edit your question with the 'new' errors I'll try to help you troubleshoot. After going through all of the steps in my link I'm surprised that it's not working. Are you using an intel processor? Or an apple silicon processor (i.e. M1 or M2)? Please add your `~/.R/Makevars` content and the output of `sessionInfo()` to your question too, in case there's any relevant info that might help. Also please add the exact install command you're using. I think this is 'solvable', as it works on my system, but it might take some effort to figure out the problem – jared_mamrot Jun 05 '23 at 22:38
  • Trichophyton just to be clear- did you follow all of the instructions in @jared_mamrot's linked post? What happened? – Mark Jun 20 '23 at 22:53
  • 1
    it seems like (similar to what Trichophyton said) the only other thinkable option to try is to wipe the slate clean, by uninstalling everything, and then starting over from scratch (maybe not using conda, if indeed that is the issue). It remains to be seen if that would actually _solve_ it, because it has proved so resistant to solving so far. But seeing as others have gotten it working on similar Macs, there is no thinkable reason why it shouldn't at some point work. The issue is making sure the slate is **totally** clean when doing it. At least, that is where my thinking is at @jared_mamrot – Mark Jun 21 '23 at 01:22
  • 1
    I had an issue with OpenMP and gcc a couple of days ago that was giving me grief. I think I ended up using [this](https://mac.r-project.org/openmp/) guide (though I remember nothing working, and giving up in a huff, and then all of a sudden yesterday things were working semi-miraculously). I did install and reinstall things, and I restarted my Mac in that time, so maybe that did the trick idk! – Mark Jun 21 '23 at 01:29
  • 1
    I also had the darwin number doesn't match OS thing that Trichophyton, though for me it was being on 22 and having 21 – Mark Jun 21 '23 at 01:32
  • Thanks @MarkHill. Indeed, I'm almost convinced to buy a new computer and start again from scratch, but worried that things may still not work :-). I've been thinking a couple of times to uninstall and reinstall everything, but I'm not sure to know exactly what I should remove (OpenMP, gcc, R/RStudio, Xcode, all my files/projects built with Xcode since MacOSX12.sdk is still called, Conda/Anaconda, etc.). And I'm not sure what is the best way to uninstall things to make sure there are not some files remaining at some location that would fool the system. – Trichophyton Jun 22 '23 at 09:41
  • If you have any suggestions about what would be the reasonable things to remove and reinstall (and the best way to remove them), that would be great. If this does not work, I can still reinstall everything from scratch if things are too complicated to solve :/. Thanks to both of you for your help. – Trichophyton Jun 22 '23 at 09:52
  • hahaha that is one option! I would say the main things are `gcc` `llvm`, XCode command line tools, and OpenMP. Conda/Anaconda is great, but at this point, you are just wanting to get something up and working, and it's just one more thing that could break, so I wouldn't use it right now, if you have been using it up until now. I'm assuming you already know how to uninstall/remove those things? – Mark Jun 22 '23 at 09:58
  • for things installed with brew, it's `brew uninstall [package]` e.g. `brew uninstall gcc`. Check when it's done if the folders are removed, the ones you saw like the darwin22 one. I would also clear the `~/.R/Makevars` file, if it wouldn't be too much of an issue for other things. I can't imagine `.R` being lowercase would cause the issue, but hey, it definitely can't hurt to make it uppercase – Mark Jun 22 '23 at 10:00
  • next run this: `sudo rm -rf /Library/Developer/CommandLineTools` `sudo xcode-select --install` – Mark Jun 22 '23 at 10:08
  • the instructions I followed, I believe were these ones: https://mac.r-project.org/openmp/ – Mark Jun 22 '23 at 10:11
  • check the version of Command Line Tools you have afterwards (for me it is 14.3.1.0.1.1683849156, I'm guessing it will be the same for you. It should be at least 14. If it's not, then let me know – Mark Jun 22 '23 at 10:14
  • for deleting openmp, I'm not entirely sure the process you used, so I can't say for certain. In the guide I linked, they suggest deleting usr/local/lib/libomp.dylib usr/local/include/ompt.h usr/local/include/omp.h usr/local/include/omp-tools.h – Mark Jun 22 '23 at 10:19
  • Thanks! I edited my post and added an 11th section with everything I did so far (I just uninstalled a couple of things). However, I noticed a few things and I just wanted to make sure if I should start reinstalling everything (witn Homebrew only and not Conda ?) or if I should first remove also anaconda files (and gfortran?) that were in another location (`/opt`). I think I should first uninstall as many things as possible to make everything clear. – Trichophyton Jun 22 '23 at 19:13
  • Of note, I upgraded to MacOS Monterey something like 2-3 weeks, I don't know if it could have made things more prone to errors... – Trichophyton Jun 22 '23 at 19:14
  • The version of Command Line Tools is 14.2.0.0.1.1668646533. `pkgutil --pkg info=com.apple.pkg.CLTools_Executables package-id:com.apple.pkg.CLTools_Executables version: 14.2.0.0.1.1668646533`. Just one question, I installed gfortran 12-2 from (https://mac.r-project.org/tools/). It's located in `/opt/` as mentioned [here](https://github.com/R-macos/gcc-12-branch/releases) which is not a folder in `$PATH` (then `which gfortran` does not return anything). DO I need to update my `$PATH` variable in `bash_profile` or add something in `.R/Makevars` ? – Trichophyton Jun 23 '23 at 07:30
  • @MarkHill It looks like it's much much better, OpenMP seems to work and data.table package can be installed ! However, I got another error with `rxode2` installation. I don't think this is related to OpenMP support, probably there is something I forgot to reinstall ? I edited section 11 and 12 in my post. – Trichophyton Jun 23 '23 at 08:34
  • My advice would be to remove Homebrew from your `PATH` entirely, delete your `~/.R/Makevars`, follow [these](https://stackoverflow.com/questions/70638118) instructions from scratch, and try again. You really don't want to be mixing binaries from CRAN and Homebrew, which use different toolchains. FWIW, I _am_ able to install **rxode2** from sources ... – Mikael Jagan Jul 31 '23 at 20:35

2 Answers2

1

Have you tried this

https://github.com/nlmixr2/nlmixr2/discussions/26

Also I think that John may have some tips if you post on the thread there.

Matthew Fidler
  • 611
  • 3
  • 3
  • I indeed tried this and things seem much better. OpenMP seems to work with data.table but I'm getting other errors when installing `rxode2` package. I edited section 11 and 12 in my post. Thanks a lot – Trichophyton Jun 23 '23 at 08:31
  • Make sure you update StanHeaders. It seems these new errors are foming from stan. If you do that make sure to install rxode2parse then rxode2random and last rxode2. They have binary linkages. Also you probably should reinstall any stan related items – Matthew Fidler Jun 24 '23 at 11:33
  • Thanks for contributing @MatthewFidler; obviously the problem isn't solved yet, but you can have the bounty anyway :) – jared_mamrot Jun 24 '23 at 12:38
  • You can also try updating BH from cran as that may also ibteract with rxode2. – Matthew Fidler Jun 24 '23 at 13:27
  • I uninstalled `StanHeaders` and then reinstalled it (version 2.26.27), the same for `BH` (version 1.81.0-1). However, when I start reinstalling from source first`rxode2parse`, then `rxode2parse` and last `rxode2` packages, I run into the same errors `(i.e., cmath, RcppAmardillo..., etc.)` for each of them. I don't think I have any stan-related items (I just installed `Rstan` to see if this made a difference, but still the same error). Do I need extra packages I could not be aware of ? Thanks! – Trichophyton Jun 25 '23 at 12:05
  • I went [here](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started) for installing RStan but I got an error when compiling `example(stan_model, package = "rstan", run.dontrun = TRUE)`. And as for rxode2, I cannot install it from source. – Trichophyton Jun 25 '23 at 12:25
0

Original answer:

Thanks for including the extra details! I've got some ideas.

First, if you run the command which gfortran in a terminal (in the terminal app, or inside the terminal tab of Rstudio), do you get the output: "/usr/local/bin/gfortran"? Or something else?

If you get "/usr/local/bin/gfortran", and the directory "/usr/local/gfortran" exists (i.e. in the terminal cd /usr/local/gfortran; ls prints "bin include lib libexec share"), delete everything in your ~.R/Makevars and include only these lines:

LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++

Then install data.table from source again:

install.packages("data.table", type = "source")

I'm hoping that will solve the problem, but if not, please edit your question with the output of which gcc, readlink -f 'the output of "which gcc"' (e.g. readlink -f /usr/bin/gcc), readlink -f gcc and gcc --version and I'll work out the next steps.


Edit 1

Based on your sleuthing, brew successfully installed gfortran but not in /usr/local/gfortran. It's very likely installed in "/usr/local/Cellar/gcc/".

If ls /usr/local/Cellar/gcc/ has the output "13.1.0", and you change your .R/Makevars to the following, I'm fairly confident it will solve your problem:

LOC=/usr/local/Cellar/gcc/13.1.0/
CC=$(LOC)/bin/gcc-13 -fopenmp
CXX=$(LOC)/bin/g++-13 -fopenmp
CXX11=$(LOC)/bin/g++-13 -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

FLIBS=-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/13/gcc/x86_64-apple-darwin22 -L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/ -lgfortran -lquadmath -lm
CXX1X=$(LOC)/bin/g++-13
CXX98=$(LOC)/bin/g++-13
CXX14=$(LOC)/bin/g++-13
CXX17=$(LOC)/bin/g++-13

Then install data.table from source again to see if it built using openMP:

install.packages("data.table", type = "source") library(data.table) #(should get a message like "data.table 1.14.8 using >1 threads") I'm hoping that will work, but if it doesn't, next step is to check that openMP is installed and can be located by the compiler.


Edit 2

OpenMP is clearly installed, but I can't reproduce the issue with the SDK version vs command line tools, so I'm struggling to troubleshoot it. Regarding the In file included from /Library/Frameworks/R.framework/Resources/include/R.h:71, from data.table.h:3: /Library/Frameworks/R.framework/Resources/include/R_ext/Complex.h:80:6: warning: ISO C99 doesn't support unnamed structs/unions [-Wpedantic] warnings, these aren't errors and they are printed as the -pedantic flag is used; you can ignore them.

If you remove the references to SDK in your Makevars file, do you still get the 'tapi file' error? I.e. change your Makevars to the following:

LOC=/usr/local/Cellar/gcc/13.1.0/
CC=$(LOC)/bin/gcc-13 -fopenmp
CXX=$(LOC)/bin/g++-13 -fopenmp
CXX11=$(LOC)/bin/g++-13 -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/
CPPFLAGS=-I$(LOC)/include -I/usr/local/include

FLIBS=-L/usr/local/Cellar/gcc/13.1.0/lib/gcc/13/gcc/x86_64-apple-darwin21 -L/usr/local/Cellar/gcc/13.1.0/lib/gcc/current/ -lgfortran -lquadmath -lm
CXX1X=$(LOC)/bin/g++-13
CXX98=$(LOC)/bin/g++-13
CXX14=$(LOC)/bin/g++-13
CXX17=$(LOC)/bin/g++-13

Then install data.table from source again:

install.packages("data.table", type = "source")
library(data.table)
#(should get a message like "data.table 1.14.8 using >1 threads")

Edit 3

Ok! Back to a working toolchain. Next step is to try out different ~/.R/Makevars configurations and see if the tapi file error comers back, or if it finally compiles with openMP as expected:

First, try the 'complete' ~/.R/Makevars that I use (double check the version of gfortran that macrtools installed is "x86_64-apple-darwin20" using ls /usr/local/gfortran/lib/gcc/, otherwise adjust FLIBS to suit):

LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11=$(LOC)/bin/g++ -fopenmp

CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin20/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++

If that doesn't work, try deleting everything in ~/.R/Makevars and try:

LDFLAGS += -L/usr/local/Cellar/libomp/lib -lomp
CPPFLAGS += -I/usr/local/Cellar/libomp/include -Xclang -fopenmp

In both cases, if you get errors they should be a lot more informative than unsupported tapi file type.

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • I edited the post (subsection 9) with new information. Thanks so much! – Trichophyton Jun 16 '23 at 09:26
  • One last thing, ~/.R/Makevars is actually ~/.r/Makevars on my computer. But nothing improves when I replace .r by the uppercase .R. I then leave it as ~/.r/. Is there a way to understand why and how to change this darwin platform inconsistency between sessionInfo() and the current version on my computer ? – Trichophyton Jun 16 '23 at 09:40
  • I'm sorry, but for a reason I cannot explain, I get again the tapi error message even though I run again the same instructions I mentioned the first time with macrtools. I again have the MacOSX12.sdk issue. Sorry that this starts being so depressing. Is there a way to uninstall gfortran in a confident way (since it is in an unusual location), and let R know the current darwin version is 21 and not 20 ? I also don't understand why macrtools cannot find Xcode CLI despite it has installed it. Maybe because it is looking for resources related to darwin.20 and this is not what is actually running? – Trichophyton Jun 16 '23 at 10:26
  • Just a thought: could this Darwin20 vs 21 discrepancy arise because I updated MacOSX (Big Sur -> Monterey) recently ? Should I also reinstall R and RStudio ? – Trichophyton Jun 16 '23 at 10:43
  • There are so many 'moving parts' in this question; I'm honestly not sure what to try next. I'll post a bounty and see if anyone else has any good ideas. Sorry you still haven't gotten a solution, but hopefully someone else has a better approach :) – jared_mamrot Jun 16 '23 at 11:33
  • Sorry for not being successful despite all your effort. This was really appreciated! Best – Trichophyton Jun 16 '23 at 12:07