LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Unable to use gcc (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-use-gcc-863728/)

sujitkulkarni 02-19-2011 08:46 AM

Unable to use gcc
 
Hey, I am trying to use gcc. I need to compile a C prog. But I am unable to do. I have done this:

Code:

sujit@sujit-desktop:~$ gcc -Wall test.c
gcc: test.c: No such file or directory
gcc: no input files
sujit@sujit-desktop:~$

I even googled for this. But I think I am making some mistakes in specifying path. Plz assist!! :confused:

goodhombre 02-19-2011 08:56 AM

Hi,

test if the the file is in the current directory before compiling it:
Code:

ls test.c

sujitkulkarni 02-19-2011 08:59 AM

umm i tried! but it says:
Code:

sujit@sujit-desktop:~$ ls test.c
ls: cannot access test.c: No such file or directory

well, the file test.c is on my desktop! so any clue?

goodhombre 02-19-2011 09:05 AM

Hi,

Likely you are in the you home directory.
Try:
Code:

cd Desktop
ls test.c

You ca find out which is the current working directory by using pwd command.

To switch to you home directory use ~
Code:

cd ~
cd Desktop
ls test.c
gcc -Wall test.c


sujitkulkarni 02-19-2011 09:07 AM

Thanks it worked! THX A LOT!!!!!!!!!!!!
Code:

sujit@sujit-desktop:~$ cd Desktop
sujit@sujit-desktop:~/Desktop$ ls test.c
test.c
sujit@sujit-desktop:~/Desktop$ gcc -Wall test.c
sujit@sujit-desktop:~/Desktop$

NOW HOW TO RUN THE PROG?

sujitkulkarni 02-19-2011 09:15 AM

Also tell me, does conio.h and void main() work? coz it is giving me error, and its asking for int main() instead of void main().

Code:

/* FILE: test.c */
#include <stdio.h>

void main()
{
        printf("Hi!!!!!!!!!");
       
}


brianL 02-19-2011 09:15 AM

Try this:
Code:

gcc -Wall test.c -o test
./test


goodhombre 02-19-2011 09:17 AM

Hi,

Try :
Code:

chmod +x a.out
./a.out

You can specify the name of the output file by using -o option.
Code:

gcc -Wall test.c -o test.out
In most on the cases you have to make file executable using chmod +x , see man chmod form more details.

goodhombre 02-19-2011 09:23 AM

Quote:

Originally Posted by sujitkulkarni (Post 4263827)
Also tell me, does conio.h and void main() work? coz it is giving me error, and its asking for int main() instead of void main().

conio.h doesn't exist under linux , you can use system("clear"); instead of clrscr().
Regarding void main , that is just a warning message, you can ignore him.

Aquarius_Girl 02-19-2011 09:26 AM

Quote:

Originally Posted by brianL (Post 4263828)
Try this:
Code:

gcc -Wall test.c -o test
./test


Wow! I never knew you were a programmer too!

goodhombre 02-19-2011 09:27 AM

Lol

brianL 02-19-2011 09:52 AM

Quote:

Originally Posted by Anisha Kaul (Post 4263836)
Wow! I never knew you were a programmer too!

That's about my limit as far as programming goes. I can edit "Hello World" programs (any language) to output "Hello Brian, you handsome devil!". :)

ntubski 02-19-2011 02:11 PM

Quote:

Originally Posted by brianL (Post 4263859)
That's about my limit as far as programming goes. I can edit "Hello World" programs (any language) to output "Hello Brian, you handsome devil!". :)

Any language, even BF? :p
Code:

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

jayjwa 02-19-2011 03:59 PM

What about LOLCODE?

sujitkulkarni 02-20-2011 12:27 AM

Thanks
 
thanks to everybody for answering me!
So the moral of the story is,
u get o/p by issuing ./filename or
chmod +x a.out
./a.out

commands. isnt it?
Also can I know how and why a.out is created?


All times are GMT -5. The time now is 02:37 PM.