0

When I run the command gcc CCC.Cpp I get this error:

CCC.Cpp: file not recognized: file format not recognized
Collect2: error: ld returned 1 exit status"

This is the content of CCC.Cpp file:

#include <iostream>
using namespace std;
int main(){cout << "CCC";return 0;}

Error message

Lorenz Keel
  • 8,362
  • 8
  • 36
  • 49
CCC019
  • 1
  • 6
  • Please don't post screenshots of command output. Copy the text here and use code formatting: https://askubuntu.com/editing-help#code. Also add the output of `cat -A CCC.Cpp`. – muru Jul 07 '21 at 09:34
  • Please install the C++ compiler : `sudo apt install g++` ..... and use g++ for C++ code. ...... ...... https://unix.meta.stackexchange.com/questions/4086/psa-please-dont-post-images-of-text – Knud Larsen Jul 07 '21 at 09:35
  • Rename your file to `CCC.cpp` and use the command `g++` instead. – FedKad Jul 07 '21 at 09:36
  • Related: [Compiling C source file without .c suffix](https://askubuntu.com/questions/380558/compiling-c-source-file-without-c-suffix) – steeldriver Jul 07 '21 at 11:04

1 Answers1

1

You have to rename the file from CCC.Cpp to CCC.cpp first and then compile your application by G++ (C++ compiler).

Reproducible way:

sudo apt-get install g++

mv CCC.Cpp CCC.cpp
g++ CCC.cpp -o CCC
./CCC

Also you should not use root account for daily non-administrative task.

N0rbert
  • 97,162
  • 34
  • 239
  • 423
  • After installing `g++` and renaming the source file, you can use just `make CCC` instead of the `g++ ...` command. – FedKad Jul 07 '21 at 09:47