반응형

2021/02/07 - [Linux] - Linux make를 이용한 컴파일(빌드) 자동화

 

리눅스에서 소스 코드를 컴파일(빌드)할때 유용한 CMake의 간단한 사용법을 알아 보자.

 

첫 번째 헤더 파일을 만든다. (a.h)

 

헤더 파일의 소스 파일을 만든다. (a.cpp)

 

두 번째 헤더 파일을 만든다. (b.h)

 

헤더 파일의 소스 파일을 만든다. (b.cpp)

 

 

두 헤더 파일과 소스 파일을 사용하는 main() 함수가 포함된 소스 파일을 작성한다.

 

CMakeLists.txt 파일을 만든다.

 

헤더/소스 파일이 있는 디렉토리에 하위 디렉토리 build를 만들고 이동후 cmake 명령을 실행한다. (CMakeLists.txt 파일이 상위 디렉토리에 있으므로 cmake ../ 를 실행해야 한다)

 

Makefile이 생성 되면 make 명령을 실행한다. 빌드가 완료되고 실행파일(main)이 생성된다.

 

반응형
Posted by J-sean
:
반응형

2021/02/08 - [Linux] - Linux CMake를 이용한 컴파일(빌드) 자동화

 

리눅스에서 소스 코드를 컴파일(빌드)할때 유용한 make의 간단한 사용법을 알아 보자.

 

첫 번째 간단한 소스 파일을 만든다. (a.cpp)

 

두 번째 간단한 소스 파일을 만든다. (b.cpp)

 

Makefile을 만든다.

 

더보기

target … : prerequisites …
             recipe
             …
             …

A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ‘clean’ (see Phony Targets).
A prerequisite is a file that is used as input to create the target. A target often depends on several files.
A recipe is an action that make carries out. A recipe may have more than one command, either on the same line or each on its own line. Please note: you need to put a tab character at the beginning of every recipe line! This is an obscurity that catches the unwary. If you prefer to prefix your recipes with a character other than tab, you can set the .RECIPEPREFIX variable to an alternate character.

 

3개의 파일이 생성 되었다. 'make runme'를 실행하면 모든 소스 코드가 컴파일 되고 빌드되어 실행파일(runme)이 생성 된다.

 

 

'make clean'을 실행하면 소스 코드 및 Makefile을 제외한 모든 파일이 정리된다.

 

이번엔 Makefile의 'runme: ...' 부분을 제일 위로 옮긴다.

 

'make runme'가 아닌 'make' 명령만으로도 빌드가 완료 된다.

 

Makefile을 매크로와 자동변수를 사용하도록 바꿔보자.

 

make와 make clean 명령이 동일하게 실행된다.

 

반응형
Posted by J-sean
: