4

I know that you can add the c++ linker with -lstdc++ and I do this, yet I am still getting an error. fatal error: iostream: No such file or directory. Hence, gcc doesn't seem to know where to look for the headers.

What is the best way to proceed here, given that g++ is not an option?

Thanks for the help!

6
  • 6
    Why g++ is not an option? Commented Dec 21, 2015 at 22:42
  • What is the extension of your files ? .c or .cpp ? Commented Dec 21, 2015 at 22:47
  • The file that is causing the error is a cpp, everything else is a c file. Commented Dec 21, 2015 at 22:48
  • I am using gcc/CMAKE to compile the code. Commented Dec 21, 2015 at 22:51
  • And yes I know that the problem is with the compiler. I am just curious if there is a good way to make gcc aware of c++ headers such as iostream. Commented Dec 21, 2015 at 22:52

1 Answer 1

3

Yes, gcc treats a file with extension .cpp as C++ source:

$ cat test.cpp
#include <iostream>
int c;
$ gcc -c test.cpp
$

You can also explicitly specify the language with -x language:

$ mv test.cpp test.c
$ gcc -c -x c++ test.c
$

But why do you want to do this? You should have g++ available and working. If not, that sounds like an incomplete or botched installation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.