How to compile c file in linux

how to compile c file in linux

How to Compile and Run C/C++ Programs On Linux

Aug 31,  · Write your code inside this file and then press ctrl+s to save the file and ctrl+x to exit from the editor. If you are using any other GUI editor once your code is complete save it with.c extension in your home directory. Or if you saved it somewhere else provide the full path of that file while performing any operations on it. You need to compile and link the two program. First compile and create object files like this. gcc -c game.c gcc -c main.c Then you can generate executable file like this. gcc game.o main.o -o myexe You can include library files using like this. gcc game.o main.o -o myexe -lsocket -wall.

Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. I am newbie to c programming language. I have the following files in same directory under centos linux system.

Here the lsocket is the socket library and using -wall displays if any warnings while linking the code.

You require to compile the game. Also you shouldn't be returning a value from a void function. Just leave the body blank, or if you really want a return statement, just type return.

Your game. Also I can highly recommend this book when learning C also good for references for experienced programmers :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Ask Question. Asked 7 years, 2 months ago. Active 7 years, 2 months ago. Viewed 3k times. You need to compile game. Add a comment.

Active Oldest Votes. You need to compile and link the two program. First compile and create object files like this gcc -c game. Using the -Wall command has always been recommended to me, so that you will notice any warnings while compiling. You should correct your code to this: game. Also I can highly recommend this book when learning C also good for references for experienced programmers : C Programming Language, 2nd Edition by Brian W.

Kernighan ISBN Sign up or log in Sign up using Google. What are some free online movie websites up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast A curious journey from personal trainer to frontend mentor.

Featured on Meta. New onboarding for review queues. Should questions about obfuscated code be off-topic? Visit chat. Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.

Create Sample C Program

Step 1 : You write your program and save the file with a. Step 2 : You compile the program and generate the object file using gcc compiler in a terminal like this:. This was just the quick summary on how to compile and run C program in Linux. In order to run a C program in Linux, you need to have a C compiler present on your systems.

In Debian and Ubuntu-based Linux distributions, use the apt command:. Switch to directory where you have kept your C program or provide the path and then generate the object file by compiling the program:. Once you have your object file generated, run it to run the C program. It is already executable. Simple use it like this:. And it will display the desired output, if your program is correct. Every time you make a change in your program, you have to compile it first and then run the generated object file to run the C program.

I recommend using an open source code editor like Visual Studio Code or Atom. These are basically text editors and you can install add-ons to compile and run programs directly from the graphical code editor. I am using Visual Studio Code editor in this example. First thing first, install Visual Studio Code in Ubuntu from the software center. You may also check the official website for more information. I am using a sample Hello World program. Next thing you would want is to use an extension that allows you to run the C code.

Instead, I suggest using the Code Runner extension. Restart Visual Studio Code. Now, you should be able to run the C code by using one of the following way:.

When you run the program, it is compiled automatically and then run. You can see the output in terminal that is opened at the bottom of the editor.

What could be better than this? Running a few C programs in Linux command line is okay but using a code editor is much easier and saves time. Also a movie buff with a soft corner for film noir.

The ext command only works in the command palette of VS Code. Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page. How do you program in C on Linux? It is indeed very easy and consists of three simple steps. Right click the program file and choose Run Code. Program output is displayed in the bottom section of the editor. Like what you read? Please share it with others. What next??

Policies Affiliate Policy Privacy Policy. Close dialog. Session expired Please log in again. Copy link. Copy Copied.





More articles in this category:
<- How to not be car sick - How do you get to faraway island in emerald->


4 thoughts on “How to compile c file in linux”

  1. There were no filew in my regBack directory. So i guess i have to do the system restore then.

  2. Hell no brother I havent bought a single cod in years. Only played a bit of warzone. Escape from tarkov masterrace.

Add a comment

Your email will not be published. Required fields are marked *