Skip to contentSkip to conversation

Mistake With CPP File

DISCUSSION SoloCDM 2 participants 8 messages Jul 31, 2002 – Aug 2, 2002

lore
Share & tools
lore

SoloCDM

author
#0 lore raw

Recently I tried to compile fig01_02.cpp with Kernel 2.2.20 on Linux Mandrake 8.0. I used "gcc fig01_02.cpp" and received the following errors:

<user_account>/tmp/ccmeDWKS.o: In function `main':
<user_account>/tmp/ccmeDWKS.o(.text+0xf): undefined reference to `cout'
<user_account>/tmp/ccmeDWKS.o(.text+0x14): undefined reference to `ostream::operator<<(char const *)'collect2: ld returned 1 exit status

Why didn't it work?

I attached the file in question.

Signature · 6 lines
Note: When you reply to this message, please include the mailing
      list/newsgroup address and my email address in To:.

*********************************************************************
Signed,
SoloCDM

// Fig. 1.2: fig01_02.cpp
// A first program in C++
#include <iostream.h>

int main()

{
	cout << "Welcome to C++!\n";

	return 0;   // indicate that program ended successfully
}
#1 lore raw
Quoted 11 lines · SoloCDM

Recently I tried to compile fig01_02.cpp with Kernel 2.2.20 on Linux Mandrake 8.0. I used "gcc fig01_02.cpp" and received the following errors:

<user_account>/tmp/ccmeDWKS.o: In function `main':
<user_account>/tmp/ccmeDWKS.o(.text+0xf): undefined reference to `cout'
<user_account>/tmp/ccmeDWKS.o(.text+0x14): undefined reference to `ostream::operator<<(char const *)'collect2: ld returned 1 exit status

Why didn't it work?

cout is in libstdc++. So either you have to call "g++ fig01_02.cpp" or "gcc -lstdc++ fig01_02.cpp".

Robert

Signature · 2 lines
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:[email protected]
author
#2 lore raw

Robert Schiele stated the following:

Quoted 12 lines · SoloCDM
Quoted 10 lines

Recently I tried to compile fig01_02.cpp with Kernel 2.2.20 on Linux Mandrake 8.0. I used "gcc fig01_02.cpp" and received the following errors:

<user_account>/tmp/ccmeDWKS.o: In function `main':
<user_account>/tmp/ccmeDWKS.o(.text+0xf): undefined reference to `cout'
<user_account>/tmp/ccmeDWKS.o(.text+0x14): undefined reference to `ostream::operator<<(char const *)'collect2: ld returned 1 exit status

Quoted 4 lines
Quoted 1 line

Why didn't it work?

cout is in libstdc++. So either you have to call "g++ fig01_02.cpp" or "gcc -lstdc++ fig01_02.cpp".

It worked -- Thanks!

I couldn't help but notice how g++ linked all the way back to colorgcc. Although, colorgcc doesn't react like g++. Colorgcc won't create a.out.

What is gcc used for? I noticed it seems to have some of the same files or libraries as g++.

Signature · 6 lines
Note: When you reply to this message, please include the mailing
      list and/or newsgroup address and my email address in To:

*********************************************************************
Signed,
SoloCDM
#3 lore raw
Quoted 9 lines · SoloCDM

Robert Schiele stated the following:

Quoted 2 lines

cout is in libstdc++. So either you have to call "g++ fig01_02.cpp" or "gcc -lstdc++ fig01_02.cpp".

It worked -- Thanks!

I couldn't help but notice how g++ linked all the way back to colorgcc. Although, colorgcc doesn't react like g++. Colorgcc won't create a.out.

Sorry, but I cannot see what you wanted to tell us with this paragraph.

Quoted 2 lines

What is gcc used for? I noticed it seems to have some of the same files or libraries as g++.

gcc and g++ are the same, but gcc uses C as it's standard language, where g++ uses C++ as standard language and links standard C++ libraries without the need to specify them explicitly.

Robert

Signature · 2 lines
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:[email protected]
author
#4 lore raw

Robert Schiele stated the following:

Quoted 8 lines · SoloCDM
Quoted 6 lines

Robert Schiele stated the following:

Quoted 2 lines

cout is in libstdc++. So either you have to call "g++ fig01_02.cpp" or "gcc -lstdc++ fig01_02.cpp".

Quoted 8 lines
Quoted 5 lines

It worked -- Thanks!

I couldn't help but notice how g++ linked all the way back to colorgcc. Although, colorgcc doesn't react like g++. Colorgcc won't create a.out.

Sorry, but I cannot see what you wanted to tell us with this paragraph.

It starts the linking (ln command) with /usr/bin/g++ --> /etc/alternatives/g++ --> /usr/bin/colorg++ --> /usr/bin/colorgcc. G++ is acting as a link. If executed in the same manner as g++ to create an a.out file, without options, colorgcc doesn't execute like g++.

Quoted 6 lines
Quoted 2 lines

What is gcc used for? I noticed it seems to have some of the same files or libraries as g++.

gcc and g++ are the same, but gcc uses C as it's standard language, where g++ uses C++ as standard language and links standard C++ libraries without the need to specify them explicitly.

Is the documentation on my system to know how to use different things like "-lstdc++" with g++? What would the files be? I didn't find anything in the man page.

Signature · 6 lines
Note: When you reply to this message, please include the mailing
      list and/or newsgroup address and my email address in To:

*********************************************************************
Signed,
SoloCDM
#5 lore raw
Quoted 5 lines · SoloCDM

It starts the linking (ln command) with /usr/bin/g++ --> /etc/alternatives/g++ --> /usr/bin/colorg++ --> /usr/bin/colorgcc. G++ is acting as a link. If executed in the same manner as g++ to create an a.out file, without options, colorgcc doesn't execute like g++.

What do you have in ~/.colorgccrc?

Quoted 3 lines

Is the documentation on my system to know how to use different things like "-lstdc++" with g++? What would the files be? I didn't find anything in the man page.

Try "info gcc".

Robert

Signature · 2 lines
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:[email protected]
author
#6 lore raw

Robert Schiele stated the following:

Quoted 10 lines · SoloCDM
Quoted 6 lines

It starts the linking (ln command) with /usr/bin/g++ --> /etc/alternatives/g++ --> /usr/bin/colorg++ --> /usr/bin/colorgcc. G++ is acting as a link. If executed in the same manner as g++ to create an a.out file, without options, colorgcc doesn't execute like g++.

What do you have in ~/.colorgccrc?

No such file exists. Everything for g++ and gcc is exactly as it was installed.

Signature · 6 lines
Note: When you reply to this message, please include the mailing
      list and/or newsgroup address and my email address in To:

*********************************************************************
Signed,
SoloCDM
#7 lore raw
Quoted 10 lines · SoloCDM

Robert Schiele stated the following:

Quoted 9 lines · SoloCDM
Quoted 6 lines

It starts the linking (ln command) with /usr/bin/g++ --> /etc/alternatives/g++ --> /usr/bin/colorg++ --> /usr/bin/colorgcc. G++ is acting as a link. If executed in the same manner as g++ to create an a.out file, without options, colorgcc doesn't execute like g++.

Quoted 4 lines
Quoted 1 line

What do you have in ~/.colorgccrc?

No such file exists. Everything for g++ and gcc is exactly as it was installed.

Then your installation of colorgcc is braindead, as you have an infinite loop, because colorgcc runs /usr/bin/g++ by default, which is itself in your case. You need to specify the path to your real g++ in the config file.

Robert

Signature · 2 lines
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:[email protected]