# Makefile in action

สร้างไฟล์โปรแกรมจำนวน 3 ไฟล์ ได้แก่

* hello.cpp
* function.h
* main.cpp

```c
// hello.cpp

#include <iostream>
#include "function.h"
using namespace std;

void print_hello()
{
   cout << "Hello World" << endl;
}
```

```c
// function.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

void print_hello();

#endif
```

```c
// main.cpp

#include <iostream>
#include "function.h"
using namespace std;

// main() is where program execution begins.
int main() {

	print_hello();
	return 0;
}
```

หลังจากนั้นให้สร้างไฟล์ `Makefile` ดังนี้

```c
all: hello

hello:	main.o hello.o
	g++ main.o hello.o -o hello
main.o:	main.cpp
	g++ -c main.cpp
hello.o:	hello.cpp
	g++ -c hello.cpp
clean:
	rm -rf *o hello
```

หลังจากนั้นให้ทำการรันด้วยคำสั่งดังนี้

```c
$ make
g++ -c main.cpp
g++ -c hello.cpp
g++ main.o hello.o -o hello
```

```c
$ ./hello
Hello World
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/c-programming-techniques/makefile-in-action.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
