Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile c++ code with gcc?

Tags:

c++

gcc

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!

like image 977
Eman Avatar asked Oct 31 '25 06:10

Eman


1 Answers

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.

like image 182
Jens Avatar answered Nov 02 '25 20:11

Jens