Dev C++ Running Different Program

This brief tutorial explains how to compile and run C/C++ programs in GNU/Linux operating system. If you’re a student or a new Linux user coming from Microsoft platform, then you might be wondering how to run the C or C++ programs in a Linux distribution. Because, compiling and running code in Linux platforms is little bit different than Windows. Let us get started, shall we?

Setup Development Environment

The g command actually runs the same compiler as gcc, but with different options directing it to compile C. (You can compile C programs with the gcc command if you know a bunch of obscure options to type on the command line, or you can just let g do it for you.).

Dev C Running Different Program In California

As you may already know, we need to install the necessary tools and compilers to run the code, right? Yes! Refer the following guide to install all development tools in your Linux box.

Dev

The development tools includes all necessary applications, such as GNU GCC C/C++ compilers, make, debuggers, man pages and others which are needed to compile and build new software, packages etc.

Also, there is a script named ‘manji’ that helps you to setup a complete environment in Ubuntu-based systems.

How To Run Program On Dev C++

After installing the necessary development tools, verify them using any one of the following commands:

These commands will display the installation path and version of gcc compiler.

Compile And Run C, C++ Programs In Linux

First, let us see how to compile and run a simple program written in C language.

Compile And Run C Programs

Write your code/program in your favorite CLI/GUI editor.

I am going to write my C program using nano editor.

Note: You need to use extension .c for C programs or .cpp for C++ programs.

Copy/paste the following code:

Press Ctrl+O and Ctrl+X to save and quit the file.

To compile the program, run:

Or,

Running

If there are any syntax or semantic errors in your code/program, they will be displayed. You need to fix them first to proceed further. If there is no error then the compiler will successfully generate an executable file named ostechnix in the current working directory.

Finally, execute the program using command:

You will see an output like below:

To compile multiple source files (Eg. source1 and source2) into executable, run:

To allow warnings, debug symbols in the output:

To compile the source code into Assembler instructions:

To compile the source code without linking:

Program

The above command will create a executable called source.o.

If your program contains math functions:

For more details, refer the man pages.

Compile And Run C++ Programs

Write your C++ program in any editor of your choice and save it with extension .cpp.

Here is a simple C++ program.

Dev C++ How To Run A Program

To compile this C++ program in Linux, simply run:

If there were no errors, you can run this C++ program under Linux using command:

Sample output would be:

Alternatively, we can compile the above C++ program using “make” command like below.

Did you notice? I didn’t use .cpp extension in the above command to compile the program. It is not necessary to use the extension to compile C++ programs using make command.

And run it using command:

For more details, refer man pages.

Hope this helps.

Thanks for stopping by!

Help us to help you:

  • Subscribe to our Email Newsletter : Sign Up Now
  • Support OSTechNix : Donate Via PayPal
  • Download free E-Books and Videos : OSTechNix on TradePub
  • Connect with us: Reddit | Facebook | Twitter | LinkedIn|RSS feeds

Have a Good day!!

Share
-->

In C++, you can exit a program in these ways:

  • Call the exit function.
  • Call the abort function.
  • Execute a return statement from main.

exit function

The exit function, declared in <stdlib.h>, terminates a C++ program. The value supplied as an argument to exit is returned to the operating system as the program's return code or exit code. By convention, a return code of zero means that the program completed successfully. You can use the constants EXIT_FAILURE and EXIT_SUCCESS, also defined in <stdlib.h>, to indicate success or failure of your program.

Issuing a return statement from the main function is equivalent to calling the exit function with the return value as its argument.

abort function

The abort function, also declared in the standard include file <stdlib.h>, terminates a C++ program. The difference between exit and abort is that exit allows the C++ run-time termination processing to take place (global object destructors will be called), whereas abort terminates the program immediately. The abort function bypasses the normal destruction process for initialized global static objects. It also bypasses any special processing that was specified using the atexit function.

atexit function

Use the atexit function to specify actions that execute prior to program termination. No global static objects initialized prior to the call to atexit are destroyed prior to execution of the exit-processing function.

return statement in main

Issuing a return statement from main is functionally equivalent to calling the exit function. Consider the following example:

The exit and return statements in the preceding example are functionally identical. However, C++ requires that functions that have return types other than void return a value. The return statement allows you to return a value from main.

Destruction of static objects

When you call exit or execute a return statement from main, static objects are destroyed in the reverse order of their initialization (after the call to atexit if one exists). The following example shows how such initialization and cleanup works.

Example

In the following example, the static objects sd1 and sd2 are created and initialized before entry to main. After this program terminates using the return statement, first sd2 is destroyed and then sd1. The destructor for the ShowData class closes the files associated with these static objects.

Dev C++ Run Program

Another way to write this code is to declare the ShowData objects with block scope, allowing them to be destroyed when they go out of scope:

Dev Program Download

See also