tags:

views:

361

answers:

3

I have a 32 bit machine and I am running Ubuntu 9.10 on it. I have the latest gcc compiler. The problem that I am facing is that I have a library developed in 2002. The code is correct for sure but when I try to built it, it gives me errors like iostream.h cannot be found, error: fstream.h: No such file or directory etc etc. There are lots of files hence I cannot change them.

Can these errors be solved if solved I install gcc 3.0 ? If yes how to install it over my existing gcc compiler.

A: 

Why couldn't you write a script to search and replace all instances of

#include <iostream.h>

with

#include <iostream>

And the same for the others?

Update: I agree with the other answer, and the comments below... I'll leave this answer though because I don't think the statement

There are lots of files hence I cannot change them

is valid :)

John Weldon
Because it wouldn't update the code that uses the headers. The pre-standard and standardised libraries typically had numerous incompatibilities.
anon
@John - I tried that once in about 2003 I think, with some C++ code of 1992 vintage. There turned out to be a bit more too it than that. The classes aren't the same. And once it compiled, it hung at runtime, probably to do with end-of-stream condition being communicated differently. Anyway, I abandoned the effort.
Daniel Earwicker
+3  A: 

The fstream.h and similar files are pre-standard versions of the fstream and similar files specified by the C++ Standard that come with modern compilers. The two are not typically compatible. Frankly, if no-one has updated the library to comply with the standard in the last 8 years, it is unlikely to be worth using.

anon
Good point! Who's to say what other issues will remain even if updating the includes.
John Weldon
@John Weldon: In my experience, there can be some nasty and hard-to-fix issues.
David Thornley
A: 

You're dealing with a pre-standard C++ library, and you've seen it won't compile with a standard compiler. You can always try the quick work-around by creating, say, iostream.h with the two lines #include <iostream> and using namespace std;, and that may work. It isn't reliable, and may cause hard-to-find bugs that will appear at an inconvenient time.

If this is a library from somewhere else, you could see if it's been updated.

The thing to realize is that the code isn't correct anymore. It may have been correct for some implementation at some time, but it isn't now. (Are you sure it was originally for gcc 3.0? Pre-standard compilers were, well, not standard, and had a lot of oddities. Avoiding that is what standards are for.) If you do install the original system, you may be unable to interface with the library properly, and new code isn't going to work. A library that doesn't interface with modern code is of limited use.

Otherwise, you're going to have to abandon the attitude that you can't change the library, and convert it to standard C++. There will likely be quite a few bugs that are fairly easy to fix (like the scope in for (int i = 0;...)), and may be some subtler problems. The code may have been correct for a certain compiler, but it isn't now.

David Thornley