Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

gcc isn't finding iostream.h

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
radfaraf
n00b
n00b
User avatar
Posts: 55
Joined: Sat May 25, 2002 2:15 pm
Location: NJ

gcc isn't finding iostream.h

  • Quote

Post by radfaraf » Wed Jul 03, 2002 10:53 pm

I'm trying to compile some of my C++ programs for class on linux, but gcc isn't finding iostream.h

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
8O
Top
BlockFin
Tux's lil' helper
Tux's lil' helper
Posts: 107
Joined: Fri Jul 05, 2002 2:36 am

  • Quote

Post by BlockFin » Sun Jul 07, 2002 12:58 am

I'm not sure why this is happening, but as a temp fix, since you know the absolute path you can #include that.

Also, #include <g++/iostream.h> might work.
Top
trythil
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Thu Jun 06, 2002 6:04 am
Location: RHIT, Terre Haute, IN, USA
Contact:
Contact trythil
Website

  • Quote

Post by trythil » Sun Jul 07, 2002 2:38 am

Well, to be C++ Standard-conformant, you should be using <iostream> instead of <iostream.h>...but I digress. 2.95.3 fakes understanding of <iostream> (and for that matter a lot of C++) anyway :)

C++ includes are usually found in /usr/include/g++. On my system, which is using GCC 3.1, they're in /usr/include/g++-v31/. Look for anything similar in your /usr/include directory -- if nothing is there, you will have to symlink.

Alternatively, you could change your compiler options to:

g++ -I/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/include/g++ array.c array

By the way, you don't want to use -c here, if array is a stand-alone program. -c tells the compiler to generate an object file only and skip the linking process.
Top
TwoSlick
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 114
Joined: Mon Apr 22, 2002 4:06 pm
Location: Rolla, MO

  • Quote

Post by TwoSlick » Mon Jul 08, 2002 9:04 pm

I'm having the exact same problem, but I think that gcc is finding the iostream.h file. It's just screwing up in some other way. I tried including the entire path to the file, and still get the same error

Code: Select all

gcc test.cpp

Code: 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 status
However if I use:

Code: Select all

g++ test.cpp
The problems are gone. :?

Weird
-Tim
Top
rac
Bodhisattva
Bodhisattva
User avatar
Posts: 6553
Joined: Thu May 30, 2002 6:19 am
Location: Japanifornia
Contact:
Contact rac
Website

  • Quote

Post by rac » Mon Jul 08, 2002 11:59 pm

Things like "undefined refence to cout" are often a result of failure to link with the standard C++ library, by adding -lstdc++ to the link command. It's hard to say more without seeing the contents of test.cpp.

Invoking gcc as g++ should not act any differently if called on a file with a recognizable C++ suffix. Is it possible that your "gcc" and "g++" are from different versions of GCC, one of which is broken?
For every higher wall, there is a taller ladder
Top
trythil
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Thu Jun 06, 2002 6:04 am
Location: RHIT, Terre Haute, IN, USA
Contact:
Contact trythil
Website

  • Quote

Post by trythil » Tue Jul 09, 2002 12:17 am

Actually, that's the expected behavior -- g++ simply invokes gcc in, for lack of a better phrase, C++ mode. This involves, among other things, automatically linking libstdc++.

Using "gcc" by itself on a C++ source file will not work. Sometimes it's easy to recognize when you've made this mistake, sometimes it's not. GCC 3.1, in particular, likes to make a mess of the output:

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;
        }
}
If you don't know what to look for, that can be a mess.
-digression-
Actually, that rule is applicable to pretty much ANY C++ compiler errors. Templates, in particular, generate really, really disgusting compiler errors, and if you try reading over the entire error you'll just go nuts. Far better to glance at it, figure out where the problem is, and fix it. :)
-end digression-


Using g++ or adding -lstdc++ will link this correctly.

BTW, that above file was part of a small benchmark I set up to determine relative speeds of string copying and deletion in C++ and C. Results surprised me -- C++ was faster.
Last edited by trythil on Tue Jul 09, 2002 12:26 am, edited 1 time in total.
Top
rac
Bodhisattva
Bodhisattva
User avatar
Posts: 6553
Joined: Thu May 30, 2002 6:19 am
Location: Japanifornia
Contact:
Contact rac
Website

  • Quote

Post by rac » Tue Jul 09, 2002 12:25 am

trythil wrote:Using "gcc" by itself on a C++ source file will not work.
From http://gcc.gnu.org/onlinedocs/gcc-3.1/g ... king%20G++:
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
Works for me; perhaps I'm misunderstanding you.
For every higher wall, there is a taller ladder
Top
trythil
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 123
Joined: Thu Jun 06, 2002 6:04 am
Location: RHIT, Terre Haute, IN, USA
Contact:
Contact trythil
Website

  • Quote

Post by trythil » Tue Jul 09, 2002 12:27 am

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

Code: Select all

gcc -lstdc++ ...
when

Code: Select all

g++ ...
works just as well. :)
Top
Post Reply

8 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic