jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
966 stars 125 forks source link

Nvimcom install throws c99 error #426

Closed seb-mueller closed 5 years ago

seb-mueller commented 5 years ago

When try to run Nvim-R on a fresh R install using the standard <leader>rfit fails with the error below. Note, I am successfully using Nvim-R on a parallel R 3.5.1 install (and loving it :) )/ Just wanted to update R. Guess, it seems somewhat version related then.

* installing to library ‘~/R/x86_64-pc-linux-gnu-library/3.6’                                                                                                                              
* installing *source* package ‘nvimcom’ ...                                                                                                                                                          
** using staged installation                                                                                                                                                                       
** libs                                                                                                                                                                                             
gcc -I"/applications/R/R-3.6.1-shlib/include" -DNDEBUG   -I/usr/local/include  -fpic  -g -O2  -c nvimcom.c -o nvimcom.o                                                                              
nvimcom.c: In function ‘nvimcom_browser_line’:                                                                                                                                                       
nvimcom.c:441:17: error: ‘for’ loop initial declarations are only allowed in C99 mode                                                                                                             
                for(int i = 0; i < len; i++){
nvimcom.c:441:17: note: use option -std=c99 or -std=gnu99 to compile your code

Having done some research, gcc seems to be missing the --std=c99 flag (https://stackoverflow.com/questions/29338206/error-for-loop-initial-declarations-are-only-allowed-in-c99-mode). Is it possible to to include this manually if that's the culprit?

I'm using a debian 9 linux with gcc version 4.8.5 (GCC). R is 3.6.1, neovim v0.3.7 and I thing nvimcom_0.9-75 and the latest Nvim-R ( fede9ba )

Update: Going into .vim/plugged/Nvim-R/R/nvimcom/src and running

gcc -I"/applications/R/R-3.6.1-shlib/include" -DNDEBUG -I/usr/local/include -fpic -g -O2 -c nvimcom.c -o nvimcom.o --std=c99

seems to overcome the issue but throws a new one:

nvimcom.c:148:21: error: storage size of ‘hints’ isn’t known
nvimcom.c:165:30: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’
nvimcom.c:173:9: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]
nvimcom.c:177:9: warning: implicit declaration of function ‘gai_strerror’ [-Wimplicit-function-declaration]
nvimcom.c:182:42: error: dereferencing pointer to incomplete type
nvimcom.c:183:22: error: dereferencing pointer to incomplete type
nvimcom.c:183:37: error: dereferencing pointer to incomplete type
nvimcom.c:184:19: error: dereferencing pointer to incomplete type
nvimcom.c:188:26: error: dereferencing pointer to incomplete type
         if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
                          ^
nvimcom.c:188:39: error: dereferencing pointer to incomplete type
         if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1)
                                       ^
nvimcom.c:200:5: warning: implicit declaration of function ‘freeaddrinfo’ [-Wimplicit-function-declaration]
     freeaddrinfo(result);    /* No longer needed */
     ^
nvimcom.c: In function ‘nvimcom_list_env’:
nvimcom.c:581:9: warning: implicit declaration of function ‘timersub’ [-Wimplicit-function-declaration]
         timersub(&end, &begin, &tdiff1);
...
jalvesaq commented 5 years ago

The development version of nvimcom is 0.9-83: https://github.com/jalvesaq/Nvim-R/commit/0f2749b84bfbad1c31ccb46efb2ee73ef7d91688 And I'm using gcc 8.3.0.

seb-mueller commented 5 years ago

Indeed, it seemed to be due to the gcc version. I changed the path to point to gcc 6.3.0 which solved the problem! Thanks for the pointer. Really enjoying that plugin!

GRealesM commented 4 years ago

Hi! I'm experiencing a similar problem when installing Nvim-R I installed the plugin using Vim-plug, but I get a similar error message to seb-mueller. Vim version is 8.1.2141, R version is 3.6.1, and Scientific Linux 7.7 (Nitrogen). I tried to use different gcc versions, including gcc (Spack GCC) 8.3.0. I tried going to .vim/plugged/Nvim-R/R/nvimcom/src and running the following command (and getting the following error

gcc -std=c99 -I"/usr/local/software/spack/spack-0.11.2/opt/spack/linux-rhel7-x86_64/gcc-5.4.0/r-3.6.1-zrytncqvsnw5h4dl6t6njefj7otl4bg4/rlib/R/include" -DNDEBUG   -I/usr/local/include  -fpic  -g -O2  -c nvimcom.c -o nvimcom.o
nvimcom.c: In function 'nvimcom_nvimclient':
nvimcom.c:148:21: error: storage size of 'hints' isn't known
     struct addrinfo hints;
                     ^~~~~
nvimcom.c:165:30: error: invalid application of 'sizeof' to incomplete type 'struct addrinfo'
     memset(&hints, 0, sizeof(struct addrinfo));
                              ^~~~~~
nvimcom.c:173:13: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
         a = getaddrinfo(getenv("NVIM_IP_ADDRESS"), portstr, &hints, &result);
             ^~~~~~~~~~~
nvimcom.c:177:46: warning: implicit declaration of function 'gai_strerror'; did you mean 'strerror'? [-Wimplicit-function-declaration]
         REprintf("Error: getaddrinfo: %s\n", gai_strerror(a));
                                              ^~~~~~~~~~~~
                                              strerror
...

I saw that seb-mueller managed to solve it, but I'm struggling. Any idea of what may be wrong? Obrigado!

seb-mueller commented 4 years ago

I believe in my case I had gcc from conda (which was very old for some reason) in my PATH which masked the system-gcc. I thing resetting the the PATH PATH=/usr/bin:$PATH did the trick if I recall correctly. Of note, also being located in Cambridge, I could come round and show you, but then we are locked in ;)

GRealesM commented 4 years ago

I used to have these sort of conda-related problems, although I'm positive it's not the case this time

$ type -a gcc 
gcc is /usr/local/software/spack/spack-0.11.2/opt/spack/linux-rhel7-x86_64/gcc-4.8.5/gcc-5.4.0-fis24ggupugiobii56fesif2y3qulpdr/bin/gcc 
gcc is /usr/bin/gcc

Thank you for your help. I hope you're doing well during this confinement =)

jalvesaq commented 4 years ago

Perhaps missing C headers...

GRealesM commented 4 years ago

Ok, so I guess it's a problem with the compiler. I don't have much experience with C so I'd really appreciate if you could give me some advice on how to check for these missing headers. Is it common that a regular gcc installation is missing headers? Obrigado!

An update on the error message (Using gcc 9.2.0) and doing \rf in an R file in Vim, in case it helps.

* installing to library ‘/home/gr440/R-packages/3.6.1’
* installing *source* package ‘nvimcom’ ...
staged installation is only possible with locking
** using non-staged installation
** libs
gcc -std=c99 -I"/usr/local/software/spack/spack-0.11.2/opt/spack/linux-rhel7-x86_64/gcc-5.4.0/r-3.6.1-zrytncqvsnw5h4dl6t6njefj7otl4bg4/rlib/R/include" -DNDEBUG   -I/usr/local/include  -fpic  -g -O2  -c nvimcom.c -o nvimcom.o
nvimcom.c: In function 'nvimcom_nvimclient':
nvimcom.c:148:21: error: storage size of 'hints' isn't known
  148 |     struct addrinfo hints;
      |                     ^~~~~
nvimcom.c:165:30: error: invalid application of 'sizeof' to incomplete type 'struct addrinfo'
  165 |     memset(&hints, 0, sizeof(struct addrinfo));
      |                              ^~~~~~
nvimcom.c:173:13: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
  173 |         a = getaddrinfo(getenv("NVIM_IP_ADDRESS"), portstr, &hints, &result);
      |             ^~~~~~~~~~~
nvimcom.c:177:46: warning: implicit declaration of function 'gai_strerror'; did you mean 'strerror'? [-Wimplicit-function-declaration]
  177 |         REprintf("Error: getaddrinfo: %s\n", gai_strerror(a));
      |                                              ^~~~~~~~~~~~
      |                                              strerror
nvimcom.c:182:42: error: dereferencing pointer to incomplete type 'struct addrinfo'
  182 |     for (rp = result; rp != NULL; rp = rp->ai_next) {
      |                                          ^~
nvimcom.c:200:5: warning: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
  200 |     freeaddrinfo(result);    /* No longer needed */
      |     ^~~~~~~~~~~~
nvimcom.c: In function 'nvimcom_list_env':
nvimcom.c:581:9: warning: implicit declaration of function 'timersub' [-Wimplicit-function-declaration]
  581 |         timersub(&end, &begin, &tdiff1);
      |         ^~~~~~~~
nvimcom.c: In function 'nvimcom_server_thread':
nvimcom.c:1160:21: error: storage size of 'hints' isn't known
 1160 |     struct addrinfo hints;
      |                     ^~~~~
nvimcom.c:1171:9: warning: implicit declaration of function 'sigemptyset' [-Wimplicit-function-declaration]
 1171 |         sigemptyset(&set);
      |         ^~~~~~~~~~~
nvimcom.c:1172:9: warning: implicit declaration of function 'sigaddset' [-Wimplicit-function-declaration]
 1172 |         sigaddset(&set, SIGINT);
      |         ^~~~~~~~~
nvimcom.c:1173:9: warning: implicit declaration of function 'sigprocmask' [-Wimplicit-function-declaration]
 1173 |         sigprocmask(SIG_BLOCK, &set, NULL);
      |         ^~~~~~~~~~~
nvimcom.c:1173:21: error: 'SIG_BLOCK' undeclared (first use in this function)
 1173 |         sigprocmask(SIG_BLOCK, &set, NULL);
      |                     ^~~~~~~~~
nvimcom.c:1173:21: note: each undeclared identifier is reported only once for each function it appears in
nvimcom.c:1177:30: error: invalid application of 'sizeof' to incomplete type 'struct addrinfo'
 1177 |     memset(&hints, 0, sizeof(struct addrinfo));
      |                              ^~~~~~
nvimcom.c:1180:22: error: 'AI_PASSIVE' undeclared (first use in this function)
 1180 |     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
      |                      ^~~~~~~~~~
nvimcom.c:1200:43: error: dereferencing pointer to incomplete type 'struct addrinfo'
 1200 |         for (rp = res; rp != NULL; rp = rp->ai_next) {
      |                                           ^~
make: *** [nvimcom.o] Error 1
ERROR: compilation failed for package ‘nvimcom’
* removing ‘/home/gr440/R-packages/3.6.1/nvimcom’
jalvesaq commented 4 years ago

I don't know enough about gcc configuration and installation to have an idea of what might be wrong in your case. I'm a social scientist with no formal training in programming. So, my knowledge is fragmentary. I do have solved some complex issues while developing Nvim-R, but there is a lot of simple stuff that I know nothing about. That said, I make two questions below that hopefully will be helpful...

It seems that your problem is not missing header because the error message would be something like:

nvimcom.c:26:10: fatal error: netdb.h: No such file or directory

The gcc command output by Nvim-R in my system is:

gcc -I"/home/aquino/software/R-3.6.3/include" -DNDEBUG   -I/usr/local/include  -fpic  -g -O2  -c nvimcom.c -o nvimcom.o

Why your gcc is called with the -std=c99 argument? And why the include path is so long in your system?

GRealesM commented 4 years ago

Hi Jakson. I quickly fixed the issue thanks to your insightful questions! I'll explain in case this is useful for somebody in the future. I had included the -std=c99 argument mainly because @seb-mueller had used such standard and it worked for him, so I thought it would do no harm. However, for the sake of trying, I removed it and try to compile at .vim/plugged/Nvim-R/R/nvimcom/src as I did before and got no error message this time. Wow! So it worked? I opened an R file in vim did \rf... and got the same error again! Fortunately, there was a useful message suggesting me to check my ~/.R/Makevars file. I went there and among the variables there was CC=gcc -std=c99 (I probably set those variables in the past for something else). I removed the argument, tried again and this time it worked, so now I have a shiny plugin up and running! Thank you for your help, and for asking the right questions. Boa noite

jalvesaq commented 4 years ago

Thanks for the feedback!