Wednesday, August 26, 2009

Linux: Unable to compile or run C or C++ program

Linux uses gcc compiler for compiling C programs and g++ for C++ programs.If you are unable to compile or run C and C++ program in Linux terminal then follow these steps.
(1) Using vi or vim editor create a C file(should be named with .c extension) and do the same for the C++ program(should be saved as .cpp)
(2) Then compile C program using following command
$gcc -o destfile sourcefile
for example if you have created a file first.c then
$gcc -o first first.c
Your compiled file will be created as first.To run this file
$./first

For C++ use g++ command with same extensions.

If you are unable to compile or run C or C++ program OR you are getting error compiling C or C++ file that means you have not installed compiler gcc and g++ in your operating system.
Follow the steps for C:
$su

$yum install gcc

For C++
$yum install g++

This will install compilers for C and C++ for linux.I hope this will help you.

No comments:

Post a Comment

Set up gmail in outlook using app password

You might receive an error saying, "unable to connect to your outgoing server" while setting up a gmail account in outlook even wh...