I can't use gcc to compile my .c

Asked by Melzy

I finally installed my Ubuntu (Thanks for your help guys!) I'm a super newb. So, I have another problem. I can't compile using gcc in the terminal.

I just followed what we've been doing in school for ages. I typed "gcc test.c" in the terminal. It didn't compile instead it said:
 "gcc:test.c:No such file or directory
  gcc: no input file"

I'm toying with the idea that maybe I don't have gcc in my system but then how come it's not saying "command not found".

I need help.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Hanusz leszek (leszek-skynet) said :
#1

Hello,

To compile things on Ubuntu you need the build-essential package:
sudo apt-get install build-essential

Revision history for this message
Melzy (melz-mirth) said :
#2

Do I just enter this line in the terminal? O_o ...

I entered it in the terminal. It said "blah-blah.. DONE blah-blah.. DONE". I tired compiling again. This time it said:

"test.c: In function 'main':
 test.c:2 warning: incompatible implicit declaration of built-in function 'printf'
 usr/bin/ld:crt1.o No such file: No such directory
 collect2: ld returened 1 exit status"

I assure you. Nothing is wrong with my code. It was just a simple Hello world to test if gcc works.

Revision history for this message
- (a--deactivatedaccount) said :
#3

are you using c or c ++ (im not a programmer)

try, sudo apt-get install g++

Revision history for this message
Hanusz leszek (leszek-skynet) said :
#4

Yes this command has to be entered in a terminal.

Instead of using blah-blah ... It is much more useful if you copy/paste the result here so there is no misunderstanding.

The error you have indicate that you are missing the libc6-dev package which should have been installed when you used the command I gave you.

Try my command again and report the output here.

Also as you are a beginner, you should know that you should not compile software on your computer except when you don't have any other option available.

What is the program you want to compile ?
Here are explanations on how to add most of the software for Ubuntu:
https://help.ubuntu.com/community/InstallingSoftware

Revision history for this message
Melzy (melz-mirth) said :
#5

Derry, I'm using C.

Hanusz, I'm not trying to compile a software. I'm just compiling a .c file I made from the text editor. In this case, it's the hello world code. Why am I doing this? I need it for school. I have a class on OS. Part of it learning shell scripting and simulating it in C using the unistd.lib. This library is only available in UNIX system.

Here's the output on terminal after entering your command:
"Reading package lists...Done
 Building dependency tree
 Reading state information...Done
 E: couldn't find package build-essential"

Er...ins't gcc supposed to built-in in Ubuntu. There's even an item on it in the manual. I can type "man gcc" in the terminal and get a result.

Revision history for this message
Przemek K. (azrael) said :
#6

Run:
sudo apt-get update
and then:
sudo apt-get install build-essential

Revision history for this message
Hanusz leszek (leszek-skynet) said :
#7

No gcc is not included by default on Ubuntu.
You should follow the advice from Przemysław Kulczycki.

Also you have access to internet right ?

Revision history for this message
akinabalu (akinabalu) said :
#8

hi! I have the same problem. I am also new to linux. I followed Przemyslaw's instructions. It seems like it compiled but when I ran the executable file, this is what it says:

The program 'hello' can be found in the following packages:
 * hello-dbs
 * hello
 * hello-debhelper
Try: sudo apt-get install <selected package>
bash: hello: command not found

So, I tried the suggestion, and it worked. Question is why does it has to be installed? It there a shortcut?

Thanks.

Revision history for this message
Przemek K. (azrael) said :
#9

Run it by typing:
./hello
This is a proper way to run a program that is in a current directory.
What you received was an information about a sample 'hello' program that is available in the Ubuntu repositories.

Revision history for this message
akinabalu (akinabalu) said :
#10

Thanks a lot, PK!

Revision history for this message
Salman Mehdi (faqeermaulada-deactivatedaccount) said :
#11

Hi Melzy
I'm novice in Linux , I have install GCC through synaptic , But don't know how to use it , Can you tell how can I make programs in C plus compile them & use them. If you know any kind of e-book which help me to do such things , Then please tell me.

Thank you

Can you help with this problem?

Provide an answer of your own, or ask Melzy for more information if necessary.

To post a message you must log in.