xpertsavenue/WiringOP-Zero

Make Failed - ‘for’ loop initial declarations are only allowed in C99 or C11 mode

ml-hn opened this issue · 3 comments

ml-hn commented

I have a problem to compile the source under the following conditions:

Hardware: Orange Pi Zero
OS: Raspian GNU/Linux 8
uname -a
Linux OrangePI 3.4.39 #2 SMP PREEMPT Mon Nov 21 16:23:11 CST 2016 armv7l GNU/Linux

I have installed the packages "gcc" and "make" before this task.
The following output have bin received:

`orangepi@OrangePI:~~/WiringOP-Zero$ sudo ./build
./build: 4: ./build: [[: not found
wiringPi Build script

WiringPi Library
[UnInstall]
[Compile] wiringPi.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
[Compile] softPwm.c
[Compile] softTone.c
[Compile] softServo.c
[Compile] mcp23008.c
[Compile] mcp23016.c
[Compile] mcp23017.c
[Compile] mcp23s08.c
[Compile] mcp23s17.c
[Compile] sr595.c
[Compile] pcf8574.c
[Compile] pcf8591.c
[Compile] mcp3002.c
[Compile] mcp3004.c
[Compile] mcp4802.c
[Compile] mcp3422.c
[Compile] max31855.c
[Compile] max5322.c
[Compile] sn3218.c
[Compile] drcSerial.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

WiringPi Devices Library
[UnInstall]
[Compile] ds1302.c
[Compile] maxdetect.c
[Compile] piNes.c
[Compile] gertboard.c
[Compile] piFace.c
[Compile] lcd128x64.c
[Compile] lcd.c
[Compile] piGlow.c
[Compile] hx711.c
hx711.c: In function ‘hx711Read’:
hx711.c:75:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (uint8_t i = 24; i--;)
^
hx711.c:75:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
hx711.c:86:11: error: conflicting types for ‘i’
for (int i = 0; i < sGainBits[instId]; i++)
^
hx711.c:75:15: note: previous definition of ‘i’ was here
for (uint8_t i = 24; i--;)
^
hx711.c:86:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (int i = 0; i < sGainBits[instId]; i++)
^
hx711.c: In function ‘hx711ReadAverage’:
hx711.c:103:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
for (uint8_t i = 0; i < times; i++)
^
Makefile:67: recipe for target 'hx711.o' failed
make: *** [hx711.o] Error 1

Make Failed...
Please check the messages and fix any problems. If you're still stuck,
then please email all the output and as many details as you can to
projects@drogon.net
`
Can you help me to resolve this.

It says so right in the logs..
‘for’ loop initial declarations are only allowed in C99 or C11 mode

Unless you specify the C99 as the standard or move the declaration to a step earlier, it will give you the error.

You can either specify " -std = C99 " in the build flags

OR

Try moving the
for (uint8_t i = 0; i < times; i++)

declaration of the i before the loop like so

uint8_t i=0;
for(i =0 ; i < times ; i++)

for the all the messages shown above. That should fix it.

ml-hn commented

Thank you!

The compilation was completed after I inserted the declaration of the loop variable. A test by set the global variable c99 was not helpful for me.
However, the loops do not make sense because 'i' is not used within the loop.

Hi I have the same problems, I tried changing declaration in one file and I have the same error in several files...

I don't want to edit each files so,

You can either specify " -std = C99 " in the build flags

How do you do that? Which file ?

Thx