[LINUX] Let's make a Makefile and build it (super beginner)

In the middle of proceeding with the introductory book of C (no progress)

It feels like how many times I've been introduced, but I'm doing this

[Introduction to C language-From basic knowledge to the essence of computers](https://www.amazon.co.jp/C%E8%A8%80%E8%AA%9E%E6%9C%AC%E6%A0 % BC% E5% 85% A5% E9% 96% 80-% E5% 9F% BA% E7% A4% 8E% E7% 9F% A5% E8% AD% 98% E3% 81% 8B% E3% 82% 89% E3% 82% B3% E3% 83% B3% E3% 83% 94% E3% 83% A5% E3% 83% BC% E3% 82% BF% E3% 81% AE% E6% 9C% AC% E8% B3% AA% E3% 81% BE% E3% 81% A7-% E7% A8% AE% E7% 94% B0-% E5% 85% 83% E6% A8% B9 / dp / 4774196169)

make……?makefile? It's not just a compilation like a common introductory book in the street, but a makefile is created and compiled, so it's a form close to practice. (It seems to be)

I was ignorant

Even though I had actually compiled with make, I read on and thought, "I just changed the name of the executable file, so I don't need to bother to make a Makefile?" When I muttered on Twitter, there was a thankful tsukkomi saying useful for big projects with hundreds and thousands of source files.

It's quite embarrassing that I should have been indebted to make in the field so far (although it's about half a year), but I didn't know how to write it or what kind of merit it has.

How to write a Makefile

Makefile.hoge


PROGRAM = hoge
OBJS    = hoge.o
SRCS    = $(OBJS:%.o=%.c)
CC      = gcc
CFLAGS  = -g -Wall
LDFLAGS =

$(PROGRAM):$(OBJS)
     $(CC) $(CFLAGS) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LDLIBS)

There seem to be other ways to write a Makefile, so I still need to study ...

Build using Makefile

$ make -f Makefile.hoge

The build process looks like this

gcc -g -Wall -c -o hoge.o hoge.c
gcc -g -Wall -o hoge hoge.o

Now that the executable file hoge is created, it can be executed as follows.

$ ./hoge

Summary

・ Makefile is convenient for large-scale development ・ Various writing styles

…… But make There are many ways to write it, but even if you google it, the book is [O'Reilly book](https://www.amazon.co.jp/GNU-Make-%E7%AC%AC3%E7%89% 88-Robert-Mecklenburg / dp / 4873112699 / ref = asc_df_4873112699 /? Tag = jpgo-22 & linkCode = df0 & hvadid = 295678107984 & hvpos = 1o2 & hvnetw = g & hvrand = 26528690058319140 & hvpone = & hvptwo = & hvqmt = & hvptwo = & hvqmt = -523848454026 & psc = 1 & th = 1 & psc = 1) What does it mean to only come out? Is it wrong to find out?

Recommended Posts

Let's make a Makefile and build it (super beginner)
Let's write a Python program and run it
Let's make a simple game with Python 3 and iPhone
Let's make a Mac app with Tkinter and py2app
[Super easy] Let's make a LINE BOT with Python.
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.
Let's make a Discord Bot.
Let's make a rock-paper-scissors game
Associate Python Enum with a function and make it Callable
Let's make a remote rumba [Hardware]
Let's make a remote rumba [Software]
Let's make a GUI with python.
Let's make a spot sale service 2
Let's make a breakout with wxPython
Let's make a spot sale service 1
Build TOPPERS / ASP3 and try it
Make let and let's one-line programming
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Let's make a spot sale service 3
2. Make a decision tree from 0 with Python and understand it (2. Python program basics)
[Personal memo] Get data on the Web and make it a DataFrame
How to make a container name a subdomain and make it accessible in Docker
Make a decision tree from 0 with Python and understand it (4. Data structure)
Let's build a belief propagation method (Python)
Let's make a shiritori game with Python
[Remote development] Let's make it first !! (Practice 1)
Let's make a voice slowly with Python
Let's make a simple language with PLY 1
Let's make a multilingual site using flask-babel
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Let's make a combination calculation in Python
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's make a Backend plugin for Errbot
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Make a Python program a daemon and run it automatically when the OS starts
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 3] ~ Implementation of nervous breakdown ~
Generate an SSID and password, make it a QR code and throw it into Slack.
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 2] ~ Vue setup ~
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 1] ~ Django setup ~
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 6] ~ User Authentication 2 ~
Load a photo and make a handwritten sketch. With zoom function. Tried to make it.
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 5] ~ User authentication ~
I set up TensowFlow and was addicted to it, so make a note
Make a chatbot and practice to be popular.
Build a virtual environment with pyenv and venv
Let's replace UWSC with Python (5) Let's make a Robot
Let's make a module for Python using SWIG
A Python beginner made a chat bot, so I tried to summarize how to make it.