I’m trying to understand how to compile C++ programs from the command line using g++ and (eventually) Clang on Ubuntu.
I found a webpage which explains MakeFiles and I am following their directions. http://mrbook.org/tutorials/make/
I downloaded the four example files into their own directory.
- main.cpp
- hello.cpp
- factorial.cpp
- functions.h
I then went ahead and ran their example of how to manually compile without a MakeFile.
g++ main.cpp hello.cpp factorial.cpp -o hello
When I ran the command from above, I received the following error from g++:
main.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
hello.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
My only experience with writing c++ is using an IDE such as VS C++ Express or CodeBlocks. Isn’t the compiler supposed to know what iostream.h is and where to find it?
How do I get rid of this error so the program willl compile?
Thanks for any help.
Before the C++ language was standardized by the ISO, the header file was named
<iostream.h>, but when the C++98 standard was released, it was renamed to just<iostream>(without the.h). Change the code to use#include <iostream>instead and it should compile.You’ll also need to add a
using namespace std;statement to each source file (or prefix each reference to an iostream function/object with astd::specifier), since namespaces did not exist in the pre-standardized C++. C++98 put the standard library functions and objects inside thestdnamespace.