Reputation: 95
I have makefile which works with clang and fail with gcc, when I comment/uncoment clang/gcc ... I don't know why.
#CC=gcc
#CFLAGS=-I -std=gnu99 -Wall -Wextra -Werror -pedantic
CC=clang
CFLAGS=-I -std=gnu99 -Wall -Wextra -Werror -pedantic
LIBS=-lpthread -lrt
SRC=rivercrossing.c functions.c
OBJ=$(SRC:.c=.o)
DEPS=rivercrossing.h
%.o: %.c $(DEPS)
$(CC) -c -o $@ $<
rivercrossing: $(OBJ)
$(CC) $^ $(CFLAGS) $(LIBS) -o $@
.PHONY: clean
clean:
rm -f *.o rivercrossing
With gcc I have following errors:
error: ‘for’ loop initial declarations are only allowed in C99 mode
error: ISO C90 forbids mixed declarations and code [-Werror=pedantic]
int stat = 0;
^
error: C++ style comments are not allowed in ISO C90 [-Werror]
Also *.o files are not deleted, when I look to the folder they are still there. Why? Thank you for you help.
Upvotes: 1
Views: 1314
Reputation: 11
You have to use C99 mode instead of gnu99 mode or you can declare variable outside of for loop.
There is a compiler switch which enables C99 mode, which amongst other things allows declaration of a variable inside the for loop. To turn it on use the compiler switch -std=c99
Upvotes: 1