Help with brms error

Hi all,

I’m new to brms and running into a problem involving compilation. I followed all the instructions for downloading brms and rstan, but when trying to run:

fitlasso <- brm(count ~ log_Age_c + log_Base4_c * Trt_c,data = epilepsy, family = poisson(), prior = set_prior(“lasso(1)”, class = “b”))

I get the following error:

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file39b540afc9a.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file39b540afc9a.cpp 2> file39b540afc9a.cpp.err.txt’ had status 1

Any help would be greatly appreciated!!

I think brms is causing compiler errors (that in principle should never happen) to be truncated. Can you post the full error message after doing

library(rstan)
library(brms)
mc <- make_stancode(count ~ log_Age_c + log_Base4_c * Trt_c,data = epilepsy, 
                    family = poisson(), prior = set_prior('lasso(1)', class = 'b'))
stan_model(model_code = mc, verbose = TRUE)

?

Yes, here is the full error message:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file5052cde5d04.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/

This generated a lot of output too (more than I can see in the console). Would you like to see that as well? Thanks so much for your help!

Yes

here is the output: google doc

I tried posting it here but went over the character limit; so copied and pasted to google docs. Thank you!

The most relevant piece is

/usr/local/clang4/bin/../include/c++/v1/stdlib.h:94:15: fatal error: 'stdlib.h' file not found
#include_next <stdlib.h>

So, the compiler error is saying it cannot find your standard library headers and is basically completely lost. We have seen errors like this a few times in the past week, but do not know what triggers it. Did you either upgrade your operating system and / or (re)install Anaconda recently?

It can probably be overcome by adding CXX14FLAGS += -isystem /usr/include to your ~/.R/Makevars file but it would be better if we knew how it went wrong.

Thanks so much again for helping with this!

I upgraded my OS after running into this problem with the hopes that it might help. I don’t have Anaconda on my laptop, so that shouldn’t be an issue.

I tried to use your fix of adding that line of code to the ~/.R/Makevars file. It now looks like this:

The following statements are required to use the clang4 binary

LDFLAGS= -L/usr/local/clang4/lib

End clang4 inclusion statements

The following statement changes the Fortran linking path

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0

End Fortran linking path statement

The following statement changes the Fortran linking path

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0

End Fortran linking path statement

CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++

The following statement changes the Fortran linking path

FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0

End Fortran linking path statement

CXX14FLAGS += -isystem /usr/include

Unfortunately, I’m still getting the same error. Can you tell me if I added that command to the Makevars file correctly, or if there is anything else you would recommend me doing?

That looks right. Open up Spotlight and paste in stdlib.h. What is the full path to that file on your computer?

The full path is:

/opt/local/var/macports/sources/rsync.macports.org/macports/release/tarballs/base/vendor/tcl8.5.19/compat/stdlib.h

Are you sure there is not more than one stdlib.h ?

I think that’s the only one! I can’t find any others.

@coatless Do you know anything about this issue of not being able to find standard library headers on a Mac and not having a /usr/include/ directory where they would ordinarily be in. This person
( https://forums.developer.apple.com/thread/104296 ) says

From the latest Xcode 10 Beta 2 release notes.
The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for macOS headers at the standard include path: /Applications/Xcodebeta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.1 4.sdk/usr/include For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg

Yes, this is specific to macOS Mojave (10.14).

c.f. Address Header Change on macOS 10.14 (Mojave) · Issue #11 · rmacoslib/r-macos-rtools · GitHub and https://twitter.com/axiomsofxyz/status/1045463113863180290

I’m aiming to update a few components on Tuesday of this week. I’ve been a bit preoccupied.

Thanks @coatless . Sounds good. @sw123 apparently you need CXX14FLAGS += -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include instead of CXX14FALGS += -isystem /usr/include in ~/.R/Makevars .

You may also need that line in CXXFLAGS and CXX11FLAGS for other packages that use C++.

Thanks so much @bgoodri and @coatless! I’ll give that a try in ~/.R/Makevars. I really appreciate both your help!