• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C++ Compiling with OSX
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ Compiling with OSX


  • Subject: Re: C++ Compiling with OSX
  • From: Bernard Giroux <email@hidden>
  • Date: Wed, 14 Nov 2007 11:57:07 -0500

Maurizio Martinelli a écrit :
Hi all,
I am sorry to ask a question probably simple, but I can't solve this problem.
I am new with C++ and I tried to run the first simple program to get started.


The program is "Hello World":

#include <iostream.h>
// This program prints "Hello, World."
main()
{
  cout << "Hello, World.\n";
  return 0;
}

I called it primo.c, then I tried to run it:

I think that gcc assumes that files with .c extension are plain C files. Try using a .cc extension.






$ gcc primo.c primo.c:1:22: error: iostream.h: No such file or directory primo.c: In function 'main': primo.c:5: error: 'cout' undeclared (first use in this function) primo.c:5: error: (Each undeclared identifier is reported only once primo.c:5: error: for each function it appears in.)

I then tried to link the library iostream.h:

$ gcc -Wall -I/usr/include/gcc/darwin/3.3/c++/backward primo.c

In file included from primo.c:1:
/usr/include/gcc/darwin/3.3/c++/backward/iostream.h:32:20: error: iostream: No such file or directory
In file included from primo.c:1:
/usr/include/gcc/darwin/3.3/c++/backward/iostream.h:34: error: parse error before 'std'
primo.c:4: warning: return type defaults to 'int'
primo.c: In function 'main':
primo.c:5: error: 'cout' undeclared (first use in this function)
primo.c:5: error: (Each undeclared identifier is reported only once
primo.c:5: error: for each function it appears in.)


In the second output line, the compiler seems to tell me that it cannot find iostream.h, but if i execute the ls command iostream.h is there:

$ ls /usr/include/gcc/darwin/3.3/c++/backward/iostream.h
/usr/include/gcc/darwin/3.3/c++/backward/iostream.h

I also tried to run primo.c with iostream.h in the same directory but it gave me the same output of `$ gcc primo.c'

I know that this is not exactly a X11 problem, but I hope you can help me too.
I work on a iBook 12'' PPC G4 1.33GHz, Tiger 10.4.10. I have installed XCode 2.4.1.
Bye


Maurizio


------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list      (email@hidden)
This email sent to email@hidden


--
Bernard Giroux, ing., Ph.D.
Chercheur

http://geo.polymtl.ca/~giroux
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list      (email@hidden)
This email sent to email@hidden


References: 
 >C++ Compiling with OSX (From: Maurizio Martinelli <email@hidden>)

  • Prev by Date: Re: xterm and UTF-8
  • Next by Date: Re: C++ Compiling with OSX
  • Previous by thread: C++ Compiling with OSX
  • Next by thread: Re: C++ Compiling with OSX
  • Index(es):
    • Date
    • Thread