# Error while compiling model using cmdstanr on a server

**URL:** <https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827>\
**Category:** General\
**Tags:** cmdstanr\
**Created:** [June 3, 2021, 2:18am UTC](https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827 "2021-06-03T02:18:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zcai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zcai/32/10242_2.png) [@zcai](https://discourse.mc-stan.org/u/zcai)\
**Post date:** [June 3, 2021, 2:18am UTC](https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827/1 "2021-06-03T02:18:06Z")

</div>

Hi there, I try to use cmdstan installed on a server (unbuntu) by our IT team, and got the following error while compiling the testing model. Do you know how to resolve this issue? Thanks.

```stan
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

```

Compiling Stan program…  
/usr/bin/ld: src/cmdstan/main.o: relocation R\_X86\_64\_32 against `.rodata.str1.8’ can not be used when making a PIE object; recompile with -fPIC  
/usr/bin/ld: final link failed: Nonrepresentable section on output  
collect2: error: ld returned 1 exit status  
make: \*\*\* [/tmp/RtmpBPI4Fd/model-5f29146d428c] Error 1  
Error: An error occured during compilation! See the message above for more information.

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [June 3, 2021, 2:30am UTC](https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827/2 "2021-06-03T02:30:49Z")

</div>

Try adding the `-fPIC` flag to the compiler options and rebuilding cmdstan:

```r
cpp_options <- list(
  "CXXFLAGS+= -fPIC"
)
cmdstan_make_local(cpp_options = cpp_options)
rebuild_cmdstan()

```

Then trying your model again

---

<div class="post-metadata">

**Author:** ![zcai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zcai/32/10242_2.png) [@zcai](https://discourse.mc-stan.org/u/zcai)\
**Post date:** [June 3, 2021, 2:45am UTC](https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827/3 "2021-06-03T02:45:21Z")

</div>

> [@andrjohns](#):
>
> ```no-highlight
> cpp_options <- list(
> "CXXFLAGS+= -fPIC"
> )
> cmdstan_make_local(cpp_options = cpp_options)
> rebuild_cmdstan()
> 
> ```

Thanks a lot. Will try and let you know.

---

<div class="post-metadata">

**Author:** ![zcai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zcai/32/10242_2.png) [@zcai](https://discourse.mc-stan.org/u/zcai)\
**Post date:** [June 5, 2021, 11:56am UTC](https://discourse.mc-stan.org/t/error-while-compiling-model-using-cmdstanr-on-a-server/22827/4 "2021-06-05T11:56:51Z")

</div>

Sorry, it was solved right away but I forgot to reply. Thanks a gain.
