Click to See Complete Forum and Search --> : gcc errors


c94wjpn
July 16th, 2002, 09:50 AM
Hi folks! I have to use gcc now. What fun this is. At the moment I can't even get hello world to build!


#include <iostream>

int main(void) {

std::cout << "hello world" ;

}




gcc says this:
undefined reference to 'std::cout'

so I guess I need to link to a library. How do I do this?

dude_1967
July 16th, 2002, 10:06 AM
The command name g++ is aliased to the C++ compiler.

Quick Start:

1) Switch to the directory in which hello.cpp is.
2) g++ hello.cpp -O3 -Wall -o hello.out
3) ./hello.out

For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

Don't lose heart, the GNU compiler collection works.

Good luck.

Chris.

:)

dude_1967
July 16th, 2002, 10:25 AM
So here is that promised Makefile.

Place it in the directory of your source code, make sure the filename in the Makefile agrees with the sample file that you want to create and just type the command make.

In order to work effectively with the GNU compiler collection, you must eventually familiarize yourself with the GNU make facility as well as the myriad of compiler switches of gcc/g++.

Cheers.

Chris.

:)

dude_1967
July 16th, 2002, 10:26 AM
Forgot the Makefile attatchment...
Chris.

c94wjpn
July 16th, 2002, 10:51 AM
Originally posted by dude_1967
The command name g++ is aliased to the C++ compiler.

Quick Start:

1) Switch to the directory in which hello.cpp is.
2) g++ hello.cpp -O3 -Wall -o hello.out
3) ./hello.out

For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

Don't lose heart, the GNU compiler collection works.

Good luck.

Chris.

:)

Thanks for you assistance.
So this is better.
What's the diff between entering gcc hello.cpp and g++ hello cpp?
when I try to run it ./hello.out it says:

error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory.

dude_1967
July 16th, 2002, 11:04 AM
c94wjpn:

I actually always thought that gcc would alias both the C compiler as well as the C++ compiler, using the file extension to determine the appropriate language (.cc, .cpp, etc for C++).

I used GCC heavily in the early '90s and stopped until about a year or two ago. When I returned to GCC, I also had problems just like yours. I then started using gcc for C-sources and g++ for C++-sources. This seems to be necessary for the newest GCC also.

Can any other guru explain the aliasing convention of gcc and g++?

Chris.

:confused:

c94wjpn
July 16th, 2002, 11:15 AM
Originally posted by dude_1967
The command name g++ is aliased to the C++ compiler.

Quick Start:

1) Switch to the directory in which hello.cpp is.
2) g++ hello.cpp -O3 -Wall -o hello.out
3) ./hello.out

For a real quick start, I still recommend at least two compiler options -O3 (optimization level 3, the highest) and Wall (most useful, non-pedantic warnings enabled).

I recently set up a very simple makefile for a beginner here. I will find this thing, zip it up and attatch it to a later posting.

Don't lose heart, the GNU compiler collection works.

Good luck.

Chris.

:)

Thanks for you assistance.
So this is better.
What's the diff between entering gcc hello.cpp and g++ hello cpp?
when I try to run it ./hello.out it says:

error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory.

PaulWendt
July 16th, 2002, 11:58 AM
Someone wrote:
>>>
Can any other guru explain the aliasing convention of gcc and g++?
<<<

Well, the ORIGINAL intent of gcc was to be a c compiler; the acronym stood for GNU C Compiler. They expanded that vision to include other compilers; the acronym now stands for GNU Compiler Collection. They want each compiler to be more standalone now, while gcc can be used to call any of them. Note that you can still use gcc to compile/link c++ programs ... you just will need to explicitly tell gcc which libraries to link with. I use g++ because g++ uses the proper includes and libraries automatically.

PaulWendt
July 16th, 2002, 12:04 PM
Someone wrote:
>>>>>
error while loading shared libraries: libstdc++.so.3: cannot open shared object file: No such file or directory
<<<<<

What OS are you using? You probably need to make sure that the dynamic library loader environment variable is set; each OS has a different notation for this. HP-UX uses SHLIB_PATH; AIX uses LIBPATH; everything else, I think, uses LD_LIBRARY_PATH. Anyway, if you did not change the prefix [while running configure], then everything should have been installed in /usr/local/lib [and the includes in /usr/local/include/g++-v3]. Assuming everything was installed properly, you now need to make sure that your LD_LIBRARY_PATH [or equivalent] has /usr/local/lib in it.

--Paul