# Boost function in rstan

**URL:** <https://discourse.mc-stan.org/t/boost-function-in-rstan/16290>\
**Category:** RStan\
**Created:** [June 29, 2020, 8:37pm UTC](https://discourse.mc-stan.org/t/boost-function-in-rstan/16290 "2020-06-29T20:37:54Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![jstag](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jstag](https://discourse.mc-stan.org/u/jstag)\
**Post date:** [June 30, 2020, 1:56pm UTC](https://discourse.mc-stan.org/t/boost-function-in-rstan/16290/5 "2020-06-30T13:56:35Z")

</div>

I’m getting closer. I followed the example and have stripped everything back to its bare minimum. I am trying to run the following example:

```
require(rstan)

model_code <-
  '
  functions {
    real standard_normal_rng() {
      return normal_rng(0,1);
   }
  }
'

stan_model(model_code = model_code, allow_undefined = TRUE, includes = paste0('\n#include "', file.path(getwd(), 'myqgamma.hpp'), '"\n'))

```

where myqgamma.hpp contains the following:

```
#include <boost/math/distributions/gamma.hpp> 

double myqgamma(double p, double shape, double scale) {
  boost::math::gamma_distribution<> dist(shape, scale); 
  return quantile(dist, p);
}

```

I get the following error:

```
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file1e4df46976a433.cpp:6:9: warning: ISO C++11 requires whitespace after the macro name
    6 | #define STAN __SERVICES__ COMMAND_HPP#include <boost/integer/integer_log2.hpp>
      | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/jhstagge/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/Eigen/Core:383,
                 from /home/jhstagge/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/Eigen/Dense:1,
                 from /home/jhstagge/R/x86_64-pc-linux-gnu-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13,
                 from <command-line>:
/home/jhstagge/R/x86_64-pc-linux-gnu-library/4.0/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMath.h:60:39: warning: ignoring attributes on template argument ‘__m128’ [-Wignored-attributes]
   60 | template<> struct is_arithmetic<__m128> { enum { value = true }; };
      | ^
/home/jhstagge/R/x86_6
In addition: Warning message:
In system(cmd, intern = !verbose) :
  running command '/usr/lib64/R/bin/R CMD SHLIB file1e4df46976a433.cpp 2> file1e4df46976a433.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection

```

I have tracked down this error message to previous posts, [for example](https://discourse.mc-stan.org/t/stan-installed-but-example-code-fails-to-run-something-about-rtools/13390/24). I updated rstan, BH, and StanHeaders to make sure I am using the most current versions.

When I remove the includes command, the model compiles properly. So, I don’t think it is an issue with the compiler/rstan, I think it must be something in myqgamma.hpp file.

I feel like I’m almost there. Any thoughts?

---

_[View the full topic](https://discourse.mc-stan.org/t/boost-function-in-rstan/16290)._
