Compile pre c++98 project?

302 Views Asked by At

Trying to compile old (legacy) cpp project. As per https://stackoverflow.com/a/13103121/555493, this project is older than C++98!

Is there any way to compile this project without some type of (minor) refactoring?

When I run the command g++ -std=c++98 -pedantic -ggdb -c file.cxx it errs out with the error fatal error: 'iostream.h' file not found.

Note: I am not the author of the original code. Migrating to a more modern version of C++ is likely out of the question. So for now, I'm just trying to get it to compile.

I'm using brew, gcc5, on a mac El Capitan.

gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir:   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
1

There are 1 best solutions below

0
On

Is there any way to compile this project without some type of (minor) refactoring?

If you are allowed to add .h files to the project, you could create iostream.h with the following:

#ifndef MY_IOSTREAM_H
#define MY_IOSTREAM_H
#include <iostream>
using namespace std;
#endif

and then make sure that the directory where the file lives is added to the list of directories to search for #included files.

Disclaimer

This does not guarantee that you won't have to change anything else. Who knows what platform specific pre-C++98 features are used in the code base of such an old project.