Last active
August 29, 2022 11:01
-
-
Save EteimZ/7ac55016772bde919520146f363cdb05 to your computer and use it in GitHub Desktop.
Demonstrating how to use gnu make.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "ops.h" | |
| int main(){ | |
| int x = 10; | |
| int y = 5; | |
| int valA = add(x, y); | |
| int valS = sub(x, y); | |
| int valM = mul(x, y); | |
| int valD = div(x, y); | |
| printf("x = 10, y = 5 \n\n"); | |
| printf("x + y = %i \n", valA ); | |
| printf("x - y = %i \n", valS ); | |
| printf("x * y = %i \n", valM ); | |
| printf("x / y = %i \n", valD ); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CC=gcc # compiler | |
| all: mainapp | |
| mainapp: main ops | |
| $(CC) main.o ops.o -o prog | |
| main: | |
| $(CC) -c main.c | |
| ops: | |
| $(CC) -c ops.c | |
| run: | |
| ./prog | |
| clean: | |
| rm *.o prog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int add(int x, int y){ | |
| return x + y; | |
| } | |
| int sub(int x, int y){ | |
| return x - y; | |
| } | |
| int mul(int x, int y){ | |
| return x * y; | |
| } | |
| int div(int x, int y){ | |
| return x / y; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // addition | |
| int add(int x, int y); | |
| // subtraction | |
| int sub(int x, int y); | |
| // multiplication | |
| int mul(int x, int y); | |
| // division | |
| int div(int x, int y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment