Compilation error in one dimensional integration in Rstan


Hi @increasechief, I tried both but gave me same error. However, if I use the following code in my header file; I get no compilation error but it shows error in loading object as Symbol not found. The code in the header file which shows NO COMPILATION error (but some warnings):

template <typename T0__, typename T1__,typename T2__>
typename boost::math::tools::promote_args<T0__, T1__, T2__>::type
test1(const T0__& ll, const T1__& ul,const T2__& beta, const T2__& M0, std::ostream& msgs) {
    auto f2= [&](double& x, double& xc,  std::vector<double>& theta, std::vector<double>& x_r, std::vector<int>& x_i,  std::ostream& msgs) {
        return std::exp(- theta[0]*(x-theta[1]));

    double ll_new=ll;
    double ul_new=ul;
    double betan= beta;
    double M0n= M0;
    double Q = stan::math::integrate_1d(f2, ll_new, ul_new, {betan,M0n}, {},{}, msgs);
    return Q;

But the error is:

Error in dyn.load(libLFile) : 
  unable to load shared object '/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/':
  dlopen(/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/, 6): Symbol not found: __ZN36model23585cd2e591_external_namespace5test1IddN4stan4math3varEdEEN5boost4math5tools12promote_argsIT_T0_T1_T2_ffE4typeERKS8_RKS9_RKSA_RKSB_PNSt3__113basic_ostreamIcNSM_11char_traitsIcEEEE
  Referenced from: /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/
  Expected in: flat namespace
 in /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/


I already told you to use *pstream__.

I’m not quite sure why that is. I would suggest, though, that in your definition for f2 that you replace double & x with double x, double & xc with double xc, and std::vector<double>& with const std::vector<double>&. Whether or not that would help isn’t clear to me, but it’s worth a shot.

Also, what do you know about C++? It doesn’t look like you’re familiar with it, and C++ can be a rather unforgiving and treacherous language even for those who are familiar with it.

1 Like

Hi, Using the corrections (*pstream__, double x, double xc, const std::vector) did not help me. I still get the same error. However, if you see my previous comment; if I use that code; I do not get any compilation error but I get error for loading object.


Yes, here the function test1 passes the message stream.

For the rest of the error Google provided me with this:


Hi @jjramsey; ignore my previous reply. I tried your code again, this time I did not get compilation error but I get this error:

Error in dyn.load(libLFile) : 
  unable to load shared object '/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/':
  dlopen(/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/, 6): Symbol not found: __ZN36model23586b9f9c36_external_namespace5test1IddN4stan4math3varEdEEN5boost4math5tools12promote_argsIT_T0_T1_T2_ffE4typeERKS8_RKS9_RKSA_RKSB_PNSt3__113basic_ostreamIcNSM_11char_traitsIcEEEE
  Referenced from: /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/
  Expected in: flat namespace
 in /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/

. Could you tell me how to resolve this?


Hi, do you know how to unload older DLLs?



But in my case, the error message is: SYMBOL NOT FOUND. I do not understand which symbol did they not find. And how to resolve this


It is telling you it cannot find a function specialization for

boost::math::tools::promote_args<double, double, stan::math::var, double, float, float>::type 
model*_namespace::test1<double, double, stan::math::var, double>(
double const&, double const&, stan::math::var const&, double const&, std::basic_ostream<char, std::char_traits<char> >*

I believe this is because you are returning a double for Q even though it should be of type stan::math::var if any of the arguments to the function is of type stan::math::var.

Perhaps more importantly why are you doing numerical integration of e^{-\theta_0 \left(x - \theta_1\right)}, which has an analytical solution?


Just to test if I can really export external C++ function; before applying it on a much complicated model. So it’s a test case for me

1 Like

The integrate_1d function got merged into the Stan language today, so you might as well just install the development versions of stuff with

source("", echo = TRUE)
remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

and then do like

1d integration in STAN language--timeline?

I get

Error: package or namespace load failed for ‘rstan’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/u/77/ave/unix/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/':
  /u/77/ave/unix/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/ undefined symbol: _ZNK4stan4lang14local_var_type10array_lensEv
Error: loading failed
Execution halted

I’ve tried some other ways to install, too, but with the same error (or with _ZNK4stan4lang14base_expr_type11is_int_typeEv) and I haven’t been able to figure out how to fix this.


Which compiler are you using?


% g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright © 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO


It’s the same for me on g++ (Debian 8.3.0-2) 8.3.0.


Try again


Didn’t change anything…


Once again


Thanks, now it works! I was going to check if I can get the vi diagnostic to RStan (already works with CmdStan), but need to continue with that tomorrow.


When calling:

I unfortunately get the following error:

Error in git2r::clone("", file.path(path_rstan,  : 
Error in 'git2r_clone': failed to stat 'C:/Users/brillems/AppData/Local/Temp/RtmpYl93wK/git2r-14f811ab7fa3/StanHeaders/inst/include/mathlib/lib/boost_1.69.0/doc/html/boost_asio/reference/async_result_lt__std__packaged_task_lt__Result_lp_Args_ellipsis__rp__gt__comma__Signature__gt_/completion_handler_type.html': The filename or extension is too long.

I tried changing the line

path_rstan <- tempfile(pattern = "git2r-")

in the source code to

path_rstan <- tempfile(pattern = "g2r-", tmpdir = "C:\\Tmp")

so that the temporary directory was as abbreviated as possible, but it still fails. It appears Windows can’t handle the outrageously long filenames that boost wants to use?