Home > Software design >  What does "writing C program that can be compiled and executable in Linux compiled with makef
What does "writing C program that can be compiled and executable in Linux compiled with makef

Time:11-19

I haven't learned about Linux or this 'makefile'. So this is very confusing concept for me.

  1. What is the difference between C program in Windows and Linux? Are there some constraints in Linux version?

  2. What is the prerequisite of makefile?

I've already searched for the c program in linux, but it showed me only about GCC, which I don't think what the problem requires.

CodePudding user response:

When compiling a program for Linux, you most likely use the GNU GCC compiler. When compiling a program for Windows, you use the MinGW32 compiler. There are no differences in what a Linux program can do, as long as the kernel supports the specific actions. The executable you create is just a different type. There is no difference in what it can do by itself. Linux and Windows are different, but most of the time they share the same functionality.

Think about it like two different types of cars. One of them is 4x4 and is able to drive offroad, and the other one is smaller, so it could be parked easier in the city. If you compare them, you wouldn't be able to choose a better one, as both of them are good for certain cases.

Windows and Linux are like that. Both of them share almost the same functionality, but have different formats of data they use for the executables.

When programmers want to compile their program without typing out a long command, they can use something called a Makefile. It allows them to enter a simple command to compile their whole project.

A Makefile has this format (You need to put a tab before you start typing the compile command):

*output file*: *required files for compilation*
        *commands necessary for compilation*

Here is an example of a simple Makefile:

a.out: main.c obj.h pointers.h
        gcc main.c -lglfw -lGL -lGLEW -lm

When you've created the Makefile, you can run make to execute the commands you put in the file.

  • Related