Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Problems compiling cpp code with (g)cc !

Problems compiling cpp code with (g)cc !
Thread Tools
Dedicated MacNNer
Join Date: Mar 2002
Status: Offline
Reply With Quote
Oct 6, 2003, 04:16 PM
 
I've installed the December 2002 developer tools which are the latest dev tools onto 10.2.8.Here is my little test cpp program.

#include <iostream>
using namespace std
void main ()
{

}

I then try to compile the code[
[Powerbook:~/Documents] danny% cc assignment1.cpp


and get this error message .... Can't cc find the library iostream or what is wrong.Thanks in advance

assignment1.cpp:3: parse error before `void'
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h: In function `const _Tp&
std::min(const _Tp&, const _Tp& [with _Tp = size_t]':
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:793: instantiated from here
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:153: `__b' undeclared
(first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:153: (Each undeclared
identifier is reported only once for each function it appears in.)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:153: `__a' undeclared
(first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h: In function `bool
std::lexicographical_compare(_InputIter1, _InputIter1, _InputIter2,
_InputIter2) [with _InputIter1 = const signed char*, _InputIter2 = const
signed char*]':
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:805: instantiated from here
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:745: `__first1'
undeclared (first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:745: `__last1'
undeclared (first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:745: `__first2'
undeclared (first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_algobase.h:745: `__last2'
undeclared (first use this function)
/usr/include/gcc/darwin/3.1/g++-v3/cmath: In function `_Tp
std::__pow_helper(_Tp, int) [with _Tp = double]':
/usr/include/gcc/darwin/3.1/g++-v3/cmath:426: instantiated from here
/usr/include/gcc/darwin/3.1/g++-v3/cmath:399: `__n' undeclared (first use this
function)
/usr/include/gcc/darwin/3.1/g++-v3/cmath:399: `__x' undeclared (first use this
function)
/usr/include/gcc/darwin/3.1/g++-v3/cmath:399: `__cmath_power' undeclared (first
use this function)
[Powerbook:~/Documents] danny%
http://winlab.csbnet.se Visit the Mac Demo Scene.
     
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Oct 6, 2003, 04:36 PM
 
not sure of your assignment, but how about iostream.h instead of iostream..

Craig
     
DevNine  (op)
Dedicated MacNNer
Join Date: Mar 2002
Status: Offline
Reply With Quote
Oct 6, 2003, 04:56 PM
 
Thanks for the reply Craig.I've added the .h and it helps however I now get different compilation errors.

here is the code
#include <iostream.h>


int main ()
{

}


and the error

cc assignment1.cpp
ld: Undefined symbols:
std::ios_base::Init::Init[in-charge]()
std::ios_base::Init::~Init [in-charge]()
___gxx_personality_v0

strange as this compiles under borland and MsVisual Studio.net.
http://winlab.csbnet.se Visit the Mac Demo Scene.
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Oct 6, 2003, 05:33 PM
 
1. It's not compiling because it doesn't realize it's C++. gcc senses whether you've called it as 'gcc' (for C), or 'g++' (for C++).

Call
g++ assignment1.cpp

and it should work fine.

2. Use the iostream form as you did originally, not iostream.h. the dot-h is quite old and strongly discouraged.

3. In addition, you should really
(a) use int main(), as in your first example, rather than void main().
(b) throw in a 'return 0;' line to ensure that your program returns something out of main.
     
DevNine  (op)
Dedicated MacNNer
Join Date: Mar 2002
Status: Offline
Reply With Quote
Oct 6, 2003, 06:15 PM
 
worked fine.Thanks alot !
http://winlab.csbnet.se Visit the Mac Demo Scene.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2