Autor Tópico: problema com gcc  (Lida 8953 vezes)

bruno

  • Visitante
problema com gcc
« Online: 23 de Janeiro de 2006, 02:26 »
bom, mudei o texto pq o axo q o problema eh outro..nao tao facil d resolver (pra mim pelo menos)

to tentando compilar o simples programa abaixo

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv) {
  string name;
  if (argc > 1) name = argv[1];
  else cin >> name;
  cout << "Hello, " + name;
  return 0;
}

mas aparece o seguinte

bruno@ubuntu:~$ gcc teste.h -o teste
teste.h:1:20: error: iostream: Arquivo ou diretório não encontrado
teste.h:2:18: error: string: Arquivo ou diretório não encontrado

teste.h:3: error: syntax error before ‘namespace’
teste.h:3: warning: data definition has no type or storage class
teste.h: In function ‘main’:
teste.h:6: error: ‘string’ undeclared (first use in this function)
teste.h:6: error: (Each undeclared identifier is reported only once
teste.h:6: error: for each function it appears in.)
teste.h:6: error: syntax error before ‘name’
teste.h:7: error: ‘name’ undeclared (first use in this function)
teste.h:8: error: ‘cin’ undeclared (first use in this function)
teste.h:9: error: ‘cout’ undeclared (first use in this function)

mas tanto iostream e string existem e estao no lugar correto..

bruno@ubuntu:~$ locate iostream
/usr/share/info/iostream-2.95.info.gz
/usr/include/c++/4.0.2/backward/iostream.h
/usr/include/c++/4.0.2/iostream
/usr/include/g++-3/iostream.h
/usr/include/g++-3/stdiostream.h
/usr/include/g++-3/iostream

o programa q eu realmente eu quero compilar precisa d outros includes e também recebo a mesma msg, mas a pasta com includes do gcc-4.0 esta completa..

bruno@ubuntu:/usr/include/c++/4.0.2$ ls
algorithm  complex   debug                istream   sstream
backward   csetjmp   deque                iterator  stack
bits       csignal   exception            limits    stdexcept
bitset     cstdarg   exception_defines.h  list      streambuf
cassert    cstddef   ext                  locale    string
cctype     cstdio    fstream              map       tr1
cerrno     cstdlib   functional           memory    typeinfo
cfloat     cstring   i486-linux-gnu       new       utility
ciso646    ctime     iomanip              numeric   valarray
climits    cwchar    ios                  ostream   vector
clocale    cwctype   iosfwd               queue     x86_64-linux-gnu
cmath      cxxabi.h iostream             set

o gcc esta com a pasta include certa

bruno@ubuntu:~$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls --without-included-gettext --enable-threads=posix --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)

a minha pergunta:
por que ele nao esta encontrando os arquivos de include? (alguma dica? falta biblioteca? qual?)

vlw ae

bruno

  • Visitante
problema com gcc
« Resposta #1 Online: 27 de Janeiro de 2006, 17:08 »
usando o comand ldd aparece isso.. ta tudo certo??

bruno@ubuntu:~$ ldd /usr/bin/gcc
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e4e000)
        /lib/ld-linux.so.2 (0xb7f8b000)

ooooosso

Offline tfmoraes

  • Usuário Ubuntu
  • *
  • Mensagens: 441
    • Ver perfil
problema com gcc
« Resposta #2 Online: 11 de Fevereiro de 2006, 19:47 »
Eu consegui compilar o seu fonte aqui em casa. Você esqueceu de colocar o ".h" nos include. Vai ficar assim:
#include <iostream.h>
#include <string.h>
Depois para compilar faça o seguinte:
g++ codigo_fonte.c -o nome_programa

Outra coisa, você salvou o fonte como teste.h, não seria teste.c?

Matheus

  • Visitante
problema com gcc
« Resposta #3 Online: 06 de MAR?O de 2006, 15:09 »
Isso mesmo que eu observei tfmoraes...

ele não acha os includes porque eles esqueceu o .h

outra coisa que não sei se influencia é que ele salvou a fonte como .h e não como .c ^^

Offline zeroday

  • Usuário Ubuntu
  • *
  • Mensagens: 1.083
    • Ver perfil
Re: problema com gcc
« Resposta #4 Online: 18 de Agosto de 2010, 18:24 »
Alem disso vc ta usando o comando gcc , pra compilar c++ vc deve usar o g++. ;D
"Lutar sempre , vencer na medida do possível , desistir jamais."

Darcamo

  • Visitante
Re: problema com gcc
« Resposta #5 Online: 19 de Agosto de 2010, 00:07 »
Na verdade não esqueceu do .h nos includes nesse exemplo, apenas de compilar com o g++ ao invés do gcc.

As bibliotecas que fazem parte do padrão em C++, como a iostream e a string, são incluídas sem o .h.
No entanto, como um compilador c++ é compatível com a linguagem C ele irá entender bibliotecas em C.

Offline fpissarra

  • Usuário Ubuntu
  • *
  • Mensagens: 246
    • Ver perfil
    • Lost in the e-Jungle
Re: problema com gcc
« Resposta #6 Online: 29 de Agosto de 2010, 17:22 »
Seu código está correto... não tem nada que colocar .h no fim dos includes...

O problema é que você está usando o compilador errado... tente:

Código: [Selecionar]
$ g++ -o teste test.cpp
Use o g++ ao invés do gcc para compilar...

[]s
Fred

bom, mudei o texto pq o axo q o problema eh outro..nao tao facil d resolver (pra mim pelo menos)

to tentando compilar o simples programa abaixo

Código: [Selecionar]
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char** argv) {
  string name;
  if (argc > 1) name = argv[1];
  else cin >> name;
  cout << "Hello, " + name;
  return 0;
}

mas aparece o seguinte

bruno@ubuntu:~$ gcc teste.h -o teste
teste.h:1:20: error: iostream: Arquivo ou diretório não encontrado
teste.h:2:18: error: string: Arquivo ou diretório não encontrado

teste.h:3: error: syntax error before ‘namespace’
teste.h:3: warning: data definition has no type or storage class
teste.h: In function ‘main’:
teste.h:6: error: ‘string’ undeclared (first use in this function)
teste.h:6: error: (Each undeclared identifier is reported only once
teste.h:6: error: for each function it appears in.)
teste.h:6: error: syntax error before ‘name’
teste.h:7: error: ‘name’ undeclared (first use in this function)
teste.h:8: error: ‘cin’ undeclared (first use in this function)
teste.h:9: error: ‘cout’ undeclared (first use in this function)