GCC não compila (stddef.h: No such file or directory)

Iniciado por PauloDDD, 16 de Agosto de 2012, 13:43

tópico anterior - próximo tópico

PauloDDD

Olá!

Uso o Ubuntu 10.04 e estou tentando compilar o seguinte programa:
#include <stdio.h>
main(){  printf("Hello, world!\n");}


Mas...

paulo@fate$ gcc hello.c
In file included from hello.c:1:
/usr/include/stdio.h:34:21: error: stddef.h: No such file or directory
In file included from /usr/include/stdio.h:75,
                 from hello.c:1:
/usr/include/libio.h:53:21: error: stdarg.h: No such file or directory
In file included from /usr/include/stdio.h:75,
                 from hello.c:1:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before 'size_t'
/usr/include/libio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:373: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:491: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/libio.h:493: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/libio.h:495: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
In file included from hello.c:1:
/usr/include/stdio.h:296: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:302: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:314: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:321: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:349: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:354: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:357: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:363: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:365: error: format string argument not a string type
/usr/include/stdio.h:367: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:368: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:369: error: format string argument not a string type
/usr/include/stdio.h:395: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:454: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:461: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:466: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:476: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:481: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:484: error: expected declaration specifiers or '...' before '__gnuc_va_list'
/usr/include/stdio.h:639: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:642: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:652: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:682: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
/usr/include/stdio.h:688: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
/usr/include/stdio.h:710: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
/usr/include/stdio.h:712: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'


Mais informações:

paulo@fate$ sudo apt-get install build-essential
[sudo] password for paulo:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version.
The following packages were automatically installed and are no longer required:
  gambas2-gb-form libcanberra-gtk-module ubufox patchutils unixcw libaccess-bridge-java-jni libaccess-bridge-java gambas2-gb-form-dialog gambas2-runtime gambas2-gb-qt
  libcanberra-gtk0 gambas2-gb-gtk gambas2-gb-gui dpatch gambas2-gb-settings
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 21 not upgraded.


Já rodei um --reinstall também, sem sucesso.


paulo@fate$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu                                                                                                                                                                 
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)

paulo@fate$ uname -a
Linux fate 2.6.32-42-generic #95-Ubuntu SMP Wed Jul 25 15:57:54 UTC 2012 i686 GNU/Linux


Alguém sabe o que pode estar acontecendo?

Jordan_Q

Eu compilei aqui e funcionou normal. Pena que eu não sei como colocar imagem aqui no forum, caso contrário eu iria lhe mostrar.
Eu usei o gcc para compilar e deu tudo normal
Ah, umas dicas:
- faltou o return 0;, é costume colocar isso antes do ultimo ' } ' em c =)
- Além disso, faltou você também dizer qual é o tipo da função main.

vou postar o que apareceu no meu terminal:

jordan@Cerberus:~$ gcc teste.c -o teste
jordan@Cerberus:~$ ./teste
Hello, world!
jordan@Cerberus:~$

fpissarra

Dê uma olhada na saída de cpp -v também:

$ cpp -v
Using built-in specs.
COLLECT_GCC=cpp
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/cc1 -E -quiet -v -imultilib . -imultiarch x86_64-linux-gnu - -mtune=generic -march=x86-64 -fstack-protector
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.


A partir da versão 4.4.3 do gcc vc sempre pode definir uma variável de ambiente C_INCLUDE_PATH e CPP_INCLUDE_PATH com os paths para os headers que você quer que sejam "padrão" para o gcc e g++, respectivamente.

PauloDDD

fpissarra e Jordan_Q, obrigado pelas respostas! Acabei de "resolver" aqui, e o buraco era mais embaixo...

Comecei a procurar por bugs do GCC, então cheguei nesse que é bem parecido com o que estava acontecendo comigo:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37995
Resumindo: se o gcc for chamado em um diretório que tenha um subdiretório chamado "gcc" dá pau...

Depois de um...
paulo@fate:/$ which gcc
/home/paulo/.cw/def/gcc

... eu me lembrei que eu uso o Color Wrapper. Bingo.

paulo@fate:/$ echo $PATH
/home/paulo/.cw/def:/home/paulo/.cw/def:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
paulo@fate$ ls /home/paulo/.cw/def/gcc
/home/paulo/.cw/def/gcc



paulo@fate$ /usr/bin/gcc hello.c
paulo@fate$ ls
a.out


Não achei nada relacionado no Google, então espero que alguém que tenha o mesmo problema chegue aqui...

A última atividade no ticket foi anteontem (15/08/2012). Será que devo postar meu caso lá?

irtigor

Não, ele foi marcado como uma duplicata desse: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48306
...que foi marcado como resolvido nas versões 4.5+, por ex, eu estou com o gcc 4.7.1 e não consigo reproduzir.