# Custom c++ using cmdstanr?

**URL:** <https://discourse.mc-stan.org/t/custom-c-using-cmdstanr/19528>\
**Category:** CmdStan\
**Tags:** cmdstanr\
**Created:** [November 27, 2020, 10:41pm UTC](https://discourse.mc-stan.org/t/custom-c-using-cmdstanr/19528 "2020-11-27T22:41:06Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [November 30, 2020, 10:05am UTC](https://discourse.mc-stan.org/t/custom-c-using-cmdstanr/19528/7 "2020-11-30T10:05:12Z")

</div>

A drawback of the cmdstan’s approach to external C++ files is that the function need to be put inside the same namespace as the model.

So whatever you have in your external file, you need to place it in

```cpp
namespace test_model_namespace {

// .. contents of the file

}

```

The namespace is always: `"name of the model"+"_model_namespace"`.

What rstan does here is it takes the C++ file of the model, places the include inside the namespace and then compiles the model. While that approach works, I honestly dont like it very much. A cleaner solution would be to handle that in stanc compiler (see [https://github.com/stan-dev/stanc3/issues/712](https://github.com/stan-dev/stanc3/issues/712)).  
Maybe there is a way around this in the meantime.

---

_[View the full topic](https://discourse.mc-stan.org/t/custom-c-using-cmdstanr/19528)._
