gcc -c array.c array
gcc: array: No such file or directory
array.c:2: iostream.h: No such file or directory
The file is at
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++/iostream.h
but for some reason it's not finding it

Code: Select all
gcc test.cppCode: Select all
/tmp/ccgxpCGn.o: In function `main':
/tmp/ccgxpCGn.o(.text+0xc): undefined reference to `cout'
/tmp/ccgxpCGn.o(.text+0x11): undefined reference to `ostream::operator<<(int)'
collect2: ld returned 1 exit statusCode: Select all
g++ test.cpp
Code: Select all
trythil@lothlann trythil $ g++ --version
g++ (GCC) 3.1
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
trythil@lothlann trythil $ gcc test2.cpp
/tmp/cc3t45ew.o: In function `main':
/tmp/cc3t45ew.o(.text+0x18): undefined reference to `std::allocator<char>::allocator[in-charge]()'
/tmp/cc3t45ew.o(.text+0x32): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge](char const*, std::allocator<char> const&)'
/tmp/cc3t45ew.o(.text+0x45): undefined reference to `std::allocator<char>::~allocator [in-charge]()'
/tmp/cc3t45ew.o(.text+0x5e): undefined reference to `std::allocator<char>::~allocator [in-charge]()'
/tmp/cc3t45ew.o(.text+0x85): undefined reference to `operator new(unsigned)'
/tmp/cc3t45ew.o(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge]()'
/tmp/cc3t45ew.o(.text+0xbd): undefined reference to `operator delete(void*)'
/tmp/cc3t45ew.o(.text+0xd6): undefined reference to `operator delete(void*)'
/tmp/cc3t45ew.o(.text+0xe8): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cc3t45ew.o(.text+0xff): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/cc3t45ew.o(.text+0x10a): undefined reference to `operator delete(void*)'
/tmp/cc3t45ew.o(.text+0x125): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/cc3t45ew.o(.text+0x13e): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/cc3t45ew.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
trythil@lothlann trythil $ cat test2.cpp
#include <string>
using namespace std;
int main()
{
string b("This is a test string. This is only a test.");
unsigned int i;
unsigned int limit = 1000000;
string *c;
for(i = 0; i <= limit; i++)
{
c = new string(b);
delete c;
}
}
From http://gcc.gnu.org/onlinedocs/gcc-3.1/g ... king%20G++:trythil wrote:Using "gcc" by itself on a C++ source file will not work.
C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .c++, .cp, or .cxx; preprocessed C++ files use the suffix .ii. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).
Code: Select all
rac@emma$ cat afo.cp
#include <iostream>
using std::cout;
using std::endl;
int main( int argc, char ** argv ) {
cout << "hello world" << endl;
}
rac@emma$ gcc -o afo -lstdc++ afo.cp
rac@emma$ ./afo
hello world

It's possible to use gcc to compile and link C++ code. I just don't see the point in doingUsing g++ or adding -lstdc++ will link this correctly.
Code: Select all
gcc -lstdc++ ...
Code: Select all
g++ ...