rui314 / 8cc

A Small C Compiler
MIT License
6.12k stars 742 forks source link

Try user include paths before standard ones #80

Closed shinh closed 7 years ago

shinh commented 7 years ago

User defined include paths are pushed to the vector before system include paths as we handle command line flags before calling cpp_init. Iterating this vector in reverse order prefers system headers to user headers, which is wrong.

A test case:

$ echo 'int main() {}' > stdio.h $ echo '#include ' > test.c $ ./8cc -I. -c test.c && gcc test.o /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function _start': (.text+0x20): undefined reference tomain' collect2: error: ld returned 1 exit status

This partially reverts bcaf3b2648e but this was broken even before the removal of vec_unshift, I think.