아래 출처참고하세요 ~
다운원하면 가서 마우스 우클릭~~
출처 : http://blog.naver.com/PostView.nhn?blogId=imisehi&logNo=150076922823
cmake 사용법 예제
cmake는 이미 설치되어 있다고 가정한다.
디렉토리는 다음과 같은 상태 입니다.
test
- Demo
- Hello
test, test/Demo, test/Hello 폴더에 각각 CMakeLists.txt파일을 아래 내용대로 생성한다.
총 3개의 CMakeLists.txt파일을 생성한다.
test/CMakeLists.txt |
# The name of our project is "HELLO". CMakeLists files in this project can # refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and # to the root binary directory of the project as ${HELLO_BINARY_DIR}. cmake_minimum_required (VERSION 2.6) project (HELLO)
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually # cause another cmake executable to run. The same process will walk through # the project's entire directory structure. add_subdirectory (Hello) add_subdirectory (Demo) |
test/Hello/CMakeLists.txt |
# Create a library called "Hello" which includes the source file "hello.cxx". # The extension is already found. Any number of sources could be listed here. add_library (Hello hello.c) |
test/Demo/CMakeLists.txt |
# Make sure the compiler can find include files from our Hello library. include_directories (${HELLO_SOURCE_DIR}/Hello)
# Make sure the linker can find the Hello library once it is built. link_directories (${HELLO_BINARY_DIR}/Hello)
# Add executable called "helloDemo" that is built from the source files # "demo.cxx" and "demo_b.cxx". The extensions are automatically found. add_executable (helloDemo demo.c)
# Link the executable to the Hello library. target_link_libraries (helloDemo Hello) |
test/Demo, test/Hello폴더에 아래와 같은 소스코드를 작성한다.
test/Demo/demo.c |
#include<stdio.h> #include"hello.h"
int main() { hello(); return 0; }
|
test/Hello/hello.h |
#include<stdio.h>
#ifndef __HELLO_H__ #define __HELLO_H__
void hello();
#endif
|
test/Hello/hello.c |
#include"hello.h"
void hello() { printf("안녕하세요?\n"); } |
위와 같이 작성한 후 아래와 같이 cmake를 실행하여 Makefile을 만들고, 만들어진 Makefile을 사용하여 실행파일을 생성한다.
[myid@localhost test]$ cmake CMakeLists.txt
-- Configuring done
-- Generating done
-- Build files have been written to: /home/myid /test
[myid@localhost test]$ make
[ 50%] Building C object Hello/CMakeFiles/Hello.dir/hello.c.o
Linking C static library libHello.a
[ 50%] Built target Hello
[100%] Building C object Demo/CMakeFiles/helloDemo.dir/demo.c.o
Linking C executable helloDemo
[100%] Built target helloDemo
[myid@localhost test]$ cd Demo/
[myid@localhost Demo]$ ./helloDemo
안녕하세요?
[출처] cmake 사용법 예제|작성자 돌고래꿈
'Stupid Computer > 5. Linux' 카테고리의 다른 글
[리눅스] 우분투 다른 유저에게 관리자 권한 주기 (0) | 2014.02.28 |
---|---|
[우분투]리눅스에서 한글 깨질때 ~ (0) | 2014.02.28 |
[우분투] 한글 console -> 영어로 전환 ~ (0) | 2014.02.28 |
[리눅스, 우분투] 리눅스 파일 찾기 명령어 (find )예제 (0) | 2014.02.28 |
[리눅스]우분투 Samba 설치, 윈도우에서 작업하기 ! (0) | 2014.02.27 |
[리눅스] Vi 명령어 , vi 명령어 pdf파일 정리 ! (0) | 2014.02.25 |
[리눅스]쉘(Shell)이란?, 리눅스 디렉토리의 구성 및 설명 (0) | 2014.02.25 |
삼바서버설정해서 윈도우와 공유하기 (윈도우에서 코딩후 리눅스로 가져가기) (0) | 2014.02.25 |
Github, 코드 개발 기반 소셜 네트웍 (퍼온글) (0) | 2014.02.21 |
우분투 - gdb 디버거 대신 nemiver (GUI 한글폰트 지원 디버그) (0) | 2014.02.21 |