Skip to main content

Posts

Showing posts with the label makefile

Make file and including external file

Now in this section, we will create a folder to contain some extra files. 1- How to compile those files. 2- We will create a separate folder to contain the obj files. 3- We will create a separate folder to the output executable as well. Will create a folder called "api" inside the source folder: this folder will contain: mmath.h #ifndef _MMATH_H_ #define _MMATH_H_ double Add(int a, int b); #endif mmath.c #include "mmath.h" double Add(int a, int b) {     return a+b; } Let's update out main as well... main.c #include <stdio.h> #include "api/mmath.h" int main(int argc,char *argv[]) {     double res = Add(23,26);     printf("You see, u see this... I'm running\r\n");     printf("%f\r\n", res);     printf("Externals Executed\r\n");     return 0; } Now How to compile this? We need to include our custom header file as well while compiling and we also need ...

Creating Symbols in Make file

So, let us make our file make file more nice ... Now we will assign symbols, and some targets as well mobi.mk CC=gcc OUT=mobi.exe TARGET=main build:     $(CC)  $(TARGET).o -o $(OUT) compile:     $(CC) -c $(TARGET).c clean:     rm -f *.o $(OUT) now try this nice command... $ make -f ./mobi.mk clean compile build rm -f *.o mobi.exe gcc -c main.c gcc  main.o -o mobi.exe It is better to create a compilation of a module separate when working on it and compile that target only instead of compiling everything... So, for so looks good... Let's add the all target mobi.mk CC=gcc OUT=mobi.exe TARGET=main all: clean compile build build:     $(CC)  $(TARGET).o -o $(OUT) compile:     $(CC) -c $(TARGET).c clean:     rm -f *.o $(OUT) Now, we don't have to specify the targets... $ make -f ./mobi.mk rm -f *.o mobi.exe gcc -c main.c gcc  main.o -o mobi.exe

Simple Make file

I kind of hate make files... But let's start it from scratch .... I'll use gcc for the compilation on windows using cygwin ... File name: main.c #include <stdio.h> int main ( int argc , char * argv []) { printf ( "You see, u see this... I'm running" ); return 0 ; } $ gcc main.c -o mobi.exe $ ./mobi.exe You see, u see this... I'm running Great ... Let's make a make file for this. Sounds funny . So, What essentially does a make file do ? It compiles. cool... but helps to keep configuration and order once and for all. file: mobi.mk all:     gcc main.c -o mobi.exe NOTE: Use  notepad for make file... Try not using Notepad++ or u may waste sometime to figure out why. Let use make file: $ make -f ./mobi.mk gcc main.c -o mobi.exe  So for so good...