nathanRamaNoodles / backlight_dimmer

Control the backlight on the official RPF display based on a touch event.
2 stars 2 forks source link

Compile error #3

Closed frazei closed 4 years ago

frazei commented 4 years ago
$ make
cc    -c -o timeout.o timeout.c
timeout.c: In function ‘increase_brightness’:
timeout.c:299:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
     for (uint16_t i = 0; i <= max_brightness-fade_amount; i++) {
     ^
timeout.c:299:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
timeout.c:313:5: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
     for (uint16_t i = max_brightness; i > 0 + fade_amount; i--) {
     ^
timeout.c: In function ‘main’:
timeout.c:355:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (uint16_t i = 0; i < tlen; i++) {
   ^
timeout.c:365:17: error: redefinition of ‘i’
   for (uint16_t i = 0; i < num_dev; i++) {
                 ^
timeout.c:355:17: note: previous definition of ‘i’ was here
   for (uint16_t i = 0; i < tlen; i++) {
                 ^
timeout.c:365:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (uint16_t i = 0; i < num_dev; i++) {
   ^
timeout.c:379:17: error: redefinition of ‘i’
   for (uint16_t i = 0; i < num_dev; i++) {
                 ^
timeout.c:365:17: note: previous definition of ‘i’ was here
   for (uint16_t i = 0; i < num_dev; i++) {
                 ^
timeout.c:379:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (uint16_t i = 0; i < num_dev; i++) {
   ^
timeout.c:422:7: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
       for (uint16_t i = 0; i < num_dev; i++) {
       ^
timeout.c:437:7: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
       for (uint16_t i = 0; i < num_dev; i++) {
       ^
: recipe for target 'timeout.o' failed
make: *** [timeout.o] Error 1
nathanRamaNoodles commented 4 years ago

edit this line from:

$(CC)   -o  $@  $^  $(LDFLAGS)

to

$(CC)   -std=c99    -o  $@  $^  $(LDFLAGS)
frazei commented 4 years ago

Don't know why but adding -std=c99 in that line makes no difference. Anyway I've added CFLAGS=-std=c99 at the beginning of Makefiles and now it compiles with a bunch of warnings:

cc -std=c99   -c -o timeout.o timeout.c
timeout.c: In function ‘sleep_ms’:
timeout.c:103:3: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
   usleep(milliseconds * 1000);
   ^
timeout.c: In function ‘restart_xprintidle’:
timeout.c:134:3: warning: implicit declaration of function ‘popen’ [-Wimplicit-function-declaration]
   fp = popen("sudo systemctl restart display-manager", "r");
   ^
timeout.c:134:6: warning: assignment makes pointer from integer without a cast
   fp = popen("sudo systemctl restart display-manager", "r");
      ^
timeout.c:141:3: warning: implicit declaration of function ‘pclose’ [-Wimplicit-function-declaration]
   pclose(fp);
   ^
timeout.c: In function ‘disable_xenergystar’:
timeout.c:154:6: warning: assignment makes pointer from integer without a cast
   fp = popen((char *) final_command, "r");
      ^
timeout.c: In function ‘get_idle_time’:
timeout.c:176:6: warning: assignment makes pointer from integer without a cast
   fp = popen((char *) final_command, "r");
      ^
timeout.c: In function ‘get_touch_screen_id’:
timeout.c:226:6: warning: assignment makes pointer from integer without a cast
   fp = popen((char *) final_command, "r");
      ^
timeout.c: In function ‘enable_touch_screen’:
timeout.c:278:6: warning: assignment makes pointer from integer without a cast
   fp = popen((char *) final_command, "r");
      ^
cc  -o  timeout timeout.o   -lm -lpcre  -std=c99

It works!