-1

Original error:

root@vishal-HP-Notebook:/home/vishal# sudo apt-get install gcc Reading package lists... Done Building dependency tree
Reading state information... Done gcc is already the newest version (4:7.3.0-3ubuntu2). 0 upgraded, 0 newly installed, 0 to remove and 179 not upgraded. root@vishal-HP-Notebook:/home/vishal# gcc gcc: fatal error: no input files compilation terminated.

root@vishal-HP-Notebook:/home/vishal# sudo apt-get install gcc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version (4:7.3.0-3ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 179 not upgraded.
root@vishal-HP-Notebook:/home/vishal# gcc
gcc: fatal error: no input files
compilation terminated.

Following Niclas Börlin's answer:

vishal@vishal-HP-Notebook:~$ cat v.c
#include<stdio.h>
void main()
{
printf("Mudit");
}
vishal@vishal-HP-Notebook:~$ gcc v.c
vishal@vishal-HP-Notebook:~$ a.out
a.out: command not found
vishal@vishal-HP-Notebook:~$ gcc --version
gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

vishal@vishal-HP-Notebook:~$ 

HOW DO I USE IT FOR CODE BLOCKS IDE I've got a method to run on terminal

vishal@vishal-HP-Notebook:~$ cat v.c
#include<stdio.h>
void main()
{
printf("Mudit");
}
vishal@vishal-HP-Notebook:~$ gcc v.c
vishal@vishal-HP-Notebook:~$ ./a.out
Muditvishal@vishal-HP-Notebook:~$
VISHAL SINGH
  • 11
  • 1
  • 2
  • 2
    Possible duplicate of [How to compile a code in gcc, .c file is in one directory and i want to compile the code in another directory?](https://askubuntu.com/questions/951847/how-to-compile-a-code-in-gcc-c-file-is-in-one-directory-and-i-want-to-compile) – David Foerster Sep 24 '18 at 11:11
  • No duplicate but you may find [What is the Best Way to use & practice coding in C language on Ubuntu](/q/163713/175814) more helpful in general. – David Foerster Sep 24 '18 at 11:13
  • As Niclas Börlin pointed out, you should run it with `./a.out` instead of `a.out`. – Chai T. Rex Sep 24 '18 at 11:23
  • Please add the result of `ls -l a.out` and `echo $PATH`. – muclux Sep 24 '18 at 11:24
  • vishal@vishal-HP-Notebook:~$ ls -l a.out -rwxr-xr-x 1 vishal vishal 8384 Sep 24 16:46 a.out vishal@vishal-HP-Notebook:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin – VISHAL SINGH Sep 24 '18 at 11:28
  • You will have to run `./a.out` not just `a.out` .. because your current directory not are in $PATH. – Soren A Sep 24 '18 at 11:28
  • any suggestions to fix codeblocks? – VISHAL SINGH Sep 24 '18 at 11:28
  • Possible duplicate of [What is the Best Way to use & practice coding in C language on Ubuntu 12.04?](https://askubuntu.com/questions/163713/what-is-the-best-way-to-use-practice-coding-in-c-language-on-ubuntu-12-04) – karel Sep 24 '18 at 11:43

2 Answers2

1

I get the same output when I call gcc without any file names, so it looks like gcc is working.

Try gcc file.c on a file with some c code. If the code is correct, it should produce an executable file called a.out.

Niclas Börlin
  • 1,946
  • 3
  • 20
  • 32
  • root@vishal-HP-Notebook:/home/vishal# gcc v.c root@vishal-HP-Notebook:/home/vishal# a.out a.out: command not found – VISHAL SINGH Sep 24 '18 at 11:09
  • 1
    @VISHALSINGH Please don't use the `root` user for this. Even if GCC is broken, it can't be helped by running GCC as `root`. Also, please add that to your question along with the output of `cat v.c`. – Chai T. Rex Sep 24 '18 at 11:12
  • 2
    @VISHALSINGH, try ./a.out. I think that the current directory is not in the PATH by default. – Niclas Börlin Sep 24 '18 at 11:14
  • vishal@vishal-HP-Notebook:~$ cat v.c #include void main() { printf("Mudit"); } vishal@vishal-HP-Notebook:~$ gcc v.c vishal@vishal-HP-Notebook:~$ a.out a.out: command not found vishal@vishal-HP-Notebook:~$ gcc --version gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. vishal@vishal-HP-Notebook:~$ – VISHAL SINGH Sep 24 '18 at 11:15
  • vishal@vishal-HP-Notebook:~$ gcc v.c vishal@vishal-HP-Notebook:~$ ./a.out Muditvishal@vishal-HP-Notebook:~$ – VISHAL SINGH Sep 24 '18 at 11:17
  • I Want to set it default for CODEBLOCKS IDE – VISHAL SINGH Sep 24 '18 at 11:17
  • OUTPUT IN CODEBLOCKS-------------- Build: Debug in m (compiler: GNU GCC Compiler)--------------- g++ -Wall -fexceptions -g -c /home/vishal/Documents/m/main.cpp -o obj/Debug/main.o /bin/sh: 1: g++: not found Process terminated with status 127 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s)) – VISHAL SINGH Sep 24 '18 at 11:20
0

It is indeed installed

Try the command below and see your current version

> gcc --version

Next go find a tutorial on GCC or read the manual

D-unit
  • 319
  • 1
  • 15
  • I guess you mean gcc --version (two dashes). – Niclas Börlin Sep 24 '18 at 11:09
  • root@vishal-HP-Notebook:/home/vishal# gcc --version gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. root@vishal-HP-Notebook:/home/vishal# – VISHAL SINGH Sep 24 '18 at 11:11
  • Yes, you can see your version 4.8.5 (pretty old version you are running). This means GCC is installed and working. I think your next step is to read about how you can use GCC now – D-unit Sep 24 '18 at 11:15