Can compile with c++ but not with gcc

Can compile with c++ but not with gcc

Post by Erik Max Franci » Sat, 20 May 2000 04:00:00




>    Trying to learn C++.  I can compile a simple program with c++
> but not gcc.

Well, what error did you get?  It's a little hard to offer assistance
when you haven't told us what's wrong.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Love is the triumph of imagination over intelligence.
\__/ H.L. Mencken
    Physics reference / http://www.alcyone.com/max/reference/physics/
 A physics reference.

 
 
 

Can compile with c++ but not with gcc

Post by Markus Kossman » Sun, 21 May 2000 04:00:00



> Hi,
>    Trying to learn C++.  I can compile a simple program with c++
> but not gcc.  I looked at the How-To but it did not describe
> setting up the C++ library.
> gcc -v has:
> Reading specs from
> /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>    The man page talks about the difference between gcc and c++
> being in the style of linking where gcc assumes C style linking
> and g++ assumes C++ style linking.  What is this style
> difference?  The error I got when compiling, well probably
> linking was cout was undefined so I assume it could not find some
> object file where the def was.

gcc ist the frontend of the C-Compiler. So it doesn't link the C++
standard library ( which contains cout)  automatically  and you will
need to add a -lstdc++ to link with that library.  

--
Markus Kossmann                                    


 
 
 

Can compile with c++ but not with gcc

Post by David Kirkpatric » Sun, 21 May 2000 04:00:00


Hi Markus,
   You were right.  Adding -lstdc++ cured the problem.  I was not
specific in the description of the problem which was:
tmp/ccmy4nbs.o: In function main:
tmp/ccmy4nbs.o: Undefined reference to 'cout'
tmp/ccmy4nbs.o: Undefined reference to 'stream::operator(char const*)'
Thanks david



> > Hi,
> >    Trying to learn C++.  I can compile a simple program with c++
> > but not gcc.  I looked at the How-To but it did not describe
> > setting up the C++ library.
> > gcc -v has:
> > Reading specs from
> > /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
> > gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
> >    The man page talks about the difference between gcc and c++
> > being in the style of linking where gcc assumes C style linking
> > and g++ assumes C++ style linking.  What is this style
> > difference?  The error I got when compiling, well probably
> > linking was cout was undefined so I assume it could not find some
> > object file where the def was.

> gcc ist the frontend of the C-Compiler. So it doesn't link the C++
> standard library ( which contains cout)  automatically  and you will
> need to add a -lstdc++ to link with that library.

> --
> Markus Kossmann


--

 
 
 

Can compile with c++ but not with gcc

Post by David Kirkpatric » Sun, 21 May 2000 04:00:00


Hi Erik,
The problem was::

tmp/ccmy4nbs.o: In function main:
tmp/ccmy4nbs.o: Undefined reference to 'cout'
tmp/ccmy4nbs.o: Undefined reference to 'stream::operator(char const*)'

Markus Kossmann sent the answer.

gcc ist the frontend of the C-Compiler. So it doesn't link the C++
standard library ( which contains cout)  automatically  and you will
need to add a -lstdc++ to link with that library.

David



> >    Trying to learn C++.  I can compile a simple program with c++
> > but not gcc.

> Well, what error did you get?  It's a little hard to offer assistance
> when you haven't told us what's wrong.

> --

>  __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
> /  \ Love is the triumph of imagination over intelligence.
> \__/ H.L. Mencken
>     Physics reference / http://www.alcyone.com/max/reference/physics/
>  A physics reference.

--

 
 
 

1. gcc does not compile C++ code?

I got gcc2.95.3 from sunfreeware.com, installed on my Sunblade100 workstation
which runs Solaris 8, and it works pretty well for C code.  However, when I
tried to compile a C++ code, it does not work.  Look:

hostname> gcc test.cpp
Undefined                       first referenced
 symbol                             in file
cout                                /var/tmp/ccoYSFew.o
ostream::operator<<(ostream &(*)(ostream &))/var/tmp/ccoYSFew.o
endl(ostream &)                     /var/tmp/ccoYSFew.o
ostream::operator<<(char const *)   /var/tmp/ccoYSFew.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
hostname>

Sunfreeware.com seems to say it works for C, C++, Java and Fortran.  Look:

gcc-2.95.3-sol8-sparc-local.gz compiled GNU C/C++/FORTRAN/Java compiler
package installs in /usr/local. See the libiberty link also.

So, what's problem, dudes?

2. Video encoders

3. gcc won't compile C++ but will compile C, help!

4. Solaris 10 sftp problem

5. It's not bad canned meat...

6. Are There any good books on the Power PC?

7. Answer on n-th ring?

8. Can not compile programs! GCC not working

9. GCC 2.6.3 and problems compiling c++ code (iostream.h).

10. Problem compiling C++ progs using gcc 2.7.2

11. compile/link error gcc with c++

12. gcc cannot compile c++ program