Answers.Body: <p>You can set a specific compiler in <code>~/.R/Makevars</code> file, create the folder and write it down in Makevers:</p>
  <pre><code>CC = gcc -std=c99
  </code></pre>
  <p>or:</p>
  <pre><code>CC = gcc -std=gnu99
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T10:52:28.477Z
Answers.LastActivityDate: 2022-06-30T10:52:28.477Z
Answers.UserDisplayName: zorbax
Answers.Body: <p>The previous answer is correct, in that the compiler wants to be able to use <code>C99</code> to compile your library.</p>
  <p>However, the solution of putting <code>CC = gcc -std=c99</code> into your <code>~/.R/Makevars</code> is a little bit blunt, since <strong>everything</strong> that you now compile not directly from source is going to use the <code>-std=c99</code> flag. This is a recipe for some confusing and hard to track down error messages. It's a bit like installing everything in your base conda environment and waiting for everything to break.</p>
  <p>It's a safer option to use <code>withr</code>, which allows you to specify compiler flags for individual installations, keeping everything nice and neat. It works a bit like the <code>with</code> (or <code>within</code>) function in R which constructs an environment to execute some command in.</p>
  <pre><code>library(withr)
  
  with_makevars(
      c(PKG_CFLAGS = &quot;-std=c99&quot;), 
      BiocManager::install(&quot;DiffBind&quot;), 
      assignment = &quot;+=&quot;
  )
  </code></pre>
  <p>It can also be performed directly with <code>BiocManager</code>:</p>
  <pre><code>BiocManager::install(
      &quot;DiffBind&quot;, 
      configure.vars = c(&quot;CC&quot; = &quot;gcc&quot;, &quot;-std&quot; = &quot;c99&quot;)
  )
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T15:20:07.317Z
Answers.Text: Couldn't that be done via the ... argument on `BiocManager::install` that it is passed to install.packages? `BiocManager::install("DiffBind", configure.vars = c("CC" = "gcc", "-std" = "c99")` never used it but I think this is the "standard" way.
Answers.UserDisplayName: llrs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T15:22:00.130Z
Answers.Text: @llrs ah, didn't realise that. Thanks, will add to answer!
Answers.UserDisplayName: user438383
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T22:36:42.970Z
Answers.Text: I might be wrong. how the variables are passed but I think there is the option to do that via `install.packages` and by extension `BiocManager::install`
Answers.UserDisplayName: llrs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T13:55:23.667Z
Answers.LastActivityDate: 2022-06-30T15:22:39.543Z
Answers.LastEditDate: 2022-06-30T15:22:39.543Z
Answers.UserDisplayName: user438383
Body: <p>I am using</p>
  <pre><code>BiocManager::install(&quot;DiffBind&quot;)
  </code></pre>
  <p>to install the package &quot;DiffBind&quot; on CentOS_7,
  I got the error:</p>
  <pre><code>gcc -I&quot;/opt/common/CentOS_7/R/R-4.0.5/lib64/R/include&quot; -DNDEBUG -D_FILE_OFFSET_BITS=64 -I'/lila/home/lid/R/x86_64-pc-linux-gnu-library/4.0/Rhtslib/include' -I'/admin/opt/common/CentOS_7/R/R-4.0.5/lib64/R/library/Rcpp/include' -I/usr/local/include   -fpic  -g -O2  -c mergeOne.c -o mergeOne.o
  mergeOne.c: In function ‘mungeTarget’:
  mergeOne.c:341:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (int i=l;i&lt;l+r;i++) {
     ^
  mergeOne.c:341:3: note: use option -std=c99 or -std=gnu99 to compile your code
  make: *** [mergeOne.o] Error 1
  ERROR: compilation failed for package ‘DiffBind’
  </code></pre>
  <p>Can anyone tell me what should I do?
  Thanks</p>
  
Tags: <r><bioconductor>
Title: BiocManager::install("DiffBind") mergeOne.c:341:3: note: use option -std=c99 or -std=gnu99 to compile your code
ThreadText: # BiocManager::install("DiffBind") mergeOne.c:341:3: note: use option -std=c99 or -std=gnu99 to compile your code
  
  (Asked by: username_0 on 2022-06-29)
  
  I am using
  
  ```
  BiocManager::install("DiffBind")
  
  ```
  
  to install the package "DiffBind" on CentOS\_7,
  I got the error:
  
  ```
  gcc -I"/opt/common/CentOS_7/R/R-4.0.5/lib64/R/include" -DNDEBUG -D_FILE_OFFSET_BITS=64 -I'/lila/home/lid/R/x86_64-pc-linux-gnu-library/4.0/Rhtslib/include' -I'/admin/opt/common/CentOS_7/R/R-4.0.5/lib64/R/library/Rcpp/include' -I/usr/local/include   -fpic  -g -O2  -c mergeOne.c -o mergeOne.o
  mergeOne.c: In function ‘mungeTarget’:
  mergeOne.c:341:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
     for (int i=l;i<l+r;i++) {
     ^
  mergeOne.c:341:3: note: use option -std=c99 or -std=gnu99 to compile your code
  make: *** [mergeOne.o] Error 1
  ERROR: compilation failed for package ‘DiffBind’
  
  ```
  
  Can anyone tell me what should I do?
  Thanks
  
  **Tags:** r, bioconductor
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-06-30. Score: 1 | Accepted answer
  
  You can set a specific compiler in `~/.R/Makevars` file, create the folder and write it down in Makevers:
  
  ```
  CC = gcc -std=c99
  
  ```
  
  or:
  
  ```
  CC = gcc -std=gnu99
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2022-06-30. Score: 3
  
  The previous answer is correct, in that the compiler wants to be able to use `C99` to compile your library.
  
  However, the solution of putting `CC = gcc -std=c99` into your `~/.R/Makevars` is a little bit blunt, since **everything** that you now compile not directly from source is going to use the `-std=c99` flag. This is a recipe for some confusing and hard to track down error messages. It's a bit like installing everything in your base conda environment and waiting for everything to break.
  
  It's a safer option to use `withr`, which allows you to specify compiler flags for individual installations, keeping everything nice and neat. It works a bit like the `with` (or `within`) function in R which constructs an environment to execute some command in.
  
  ```
  library(withr)
  
  with_makevars(
      c(PKG_CFLAGS = "-std=c99"), 
      BiocManager::install("DiffBind"), 
      assignment = "+="
  )
  
  ```
  
  It can also be performed directly with `BiocManager`:
  
  ```
  BiocManager::install(
      "DiffBind", 
      configure.vars = c("CC" = "gcc", "-std" = "c99")
  )
  
  ```
  
  > **Comments:**
  > **username_3**: Couldn't that be done via the ... argument on `BiocManager::install` that it is passed to install.packages? `BiocManager::install("DiffBind", configure.vars = c("CC" = "gcc", "-std" = "c99")` never used it but I think this is the "standard" way.  
  > **username_2**: @username_3 ah, didn't realise that. Thanks, will add to answer!  
  > **username_3**: I might be wrong. how the variables are passed but I think there is the option to do that via `install.packages` and by extension `BiocManager::install`  
  
  ---
  
  