How to fix this compilation error?


#1

I got the following compilation error when running some brms code. How to fix this?

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 /usr/include/c++/4.8.2/thread:35:0,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file34262899c967.cpp:8:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler o
Calls: brm … cxxfunctionplus -> -> cxxfunction -> compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB file34262899c967.cpp 2> file34262899c967.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
Calls: brm … eval -> do.call -> -> cxxfunctionplus -> sink
Execution halted

  • Operating System: Red Hat 7.5
  • R version: 3.5.1
  • brms Version: 2.6.0

#2


In addition, you likely need CXX14 = g++ -std=c++1y in your ~/.R/Makevars file.


#3
  • Operating System: Red Hat 7.5
  • R version: 3.5.1
  • brms Version: 2.6.0

With the following included in the ~/.R/Makevars file:

CXX14 = g++
CXX14FLAGS = -O3 -march=native -mtune=native -fPIC

I’m still struggling with the following compilation error when running some brms code:

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 /usr/lib64/R/library/RcppEigen/include/Eigen/Core:380:0,
from /usr/lib64/R/library/RcppEigen/include/Eigen/Dense:1,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from filef4504252e3c6.cpp:8:
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMa
Calls: brm … cxxfunctionplus -> -> cxxfunction -> compileCode
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB filef4504252e3c6.cpp 2> filef4504252e3c6.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
Calls: brm … eval -> do.call -> -> cxxfunctionplus -> sink
Execution halted

What is missing?


#4

Can you do

library(rstan)
stan_model(model_code = make_stancode(...), verbose = TRUE)

calling make_stancode the same way you call brm()?


#5

Here it is:

> library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.18.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)

> stan_model(model_code = make_stancode(…), verbose = TRUE)
Error in make_stancode(…) : could not find function “make_stancode”


#6

You would need to do library(brms) first.


#7

The compilation went through almost 2000 lines, and ended up with a similar error as before:

1981: // declarations
1982: extern “C” {
1983: SEXP file9e52590d04aa( ) ;
1984: }
1985:
1986: // definition
1987:
1988: SEXP file9e52590d04aa( ){
1989: return Rcpp::wrap(“2fdbe54e992dce49149926006408144e”);
1990: }
1991:
1992:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/lib64/R/library/RcppEigen/include/Eigen/Core:380:0,
from /usr/lib64/R/library/RcppEigen/include/Eigen/Dense:1,
from /usr/lib64/R/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat/fun/Eigen_NumTraits.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core/matrix_vari.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/core.hpp:14,
from /usr/lib64/R/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/stan/math.hpp:4,
from /usr/lib64/R/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file9e52590d04aa.cpp:8:
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMa


#8

You may have to scroll up to find the line that begins with error: (with a colon)


#9

OK, how about this part? In case this is useful, I currently invoke the new C++ compiler through a terminal command of “scl enable devtoolset-7 tcsh”.

file9e52590d04aa.cpp:1990:1: required from here
/usr/lib64/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:650:34: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits::type {aka __vector(4) double}’ [-Wignored-attributes]
return internal::first_aligned<int(unpacket_traits::alignment),Derived>(m);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: file9e52590d04aa.o: relocation R_X86_64_32 against undefined symbol `__pthread_key_create’ can not be used when making a shared object; recompile with -fPIC
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/make/shlib.mk:6: file9e52590d04aa.so] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!


#10

You need

CXX14FLAGS += -fPIC

in your ~/.R/Makevars file.