Pro / raspi-toolchain

170 stars 40 forks source link

Failed to compile with "<limits.h>" #8

Closed jasonmiu closed 3 years ago

jasonmiu commented 4 years ago

I downloaded the pre-built toolchain from wget https://github.com/Pro/raspi-toolchain/releases/latest/download/raspi-toolchain.tar.gz. I cannot compile a C program that needs definitions like PATH_MAX from <limits.h> with this toolchain. Here is a minimal test case:

$ cat test.c 
#include <limits.h>
#include <stdio.h>
int main()
{
  int i = LINE_MAX;
  int p[PATH_MAX];

  return 0;
} 

Compiling with the toolchain, on the host Ubuntu 18.04.5, gave me the error:

$ arm-linux-gnueabihf-gcc -o test_lim_arm ./test.c
./test.c: In function 'main':
./test.c:5:11: error: 'LINE_MAX' undeclared (first use in this function); did you mean 'LONG_MAX'?
   int i = LINE_MAX;
           ^~~~~~~~
           LONG_MAX
./test.c:5:11: note: each undeclared identifier is reported only once for each function it appears in
./test.c:6:9: error: 'PATH_MAX' undeclared (first use in this function); did you mean 'INT_MAX'?
   int p[PATH_MAX];
         ^~~~~~~~
         INT_MAX

Same code with the native GCC compiled successfully:

$ gcc -o test_lim_x86 ./test.c

This is my toolchain info:

$ arm-linux-gnueabihf-gcc -v        
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/opt/cross-pi-gcc/libexec/gcc/arm-linux-gnueabihf/8.3.0/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../gcc-8.3.0/configure --prefix=/opt/cross-pi-gcc --target=arm-linux-gnueabihf --enable-languages=c,c++,fortran --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-multilib
Thread model: posix
gcc version 8.3.0 (GCC) 

Thanks you.

robamu commented 3 years ago

Has anyone managed to solve this?

rafal1137 commented 3 years ago

Have same issue with not defined PATH_MAX. Someone already found solution to that one here: https://github.com/abhiTronix/raspberry-pi-cross-compilers/issues/8

bernhard-guillon-copadata commented 3 years ago

I created a pull request #12 to fix that issue.

Pro commented 3 years ago

Fixed in #12