출처
http://erato1004.tistory.com/entry/eclipse에서-static-library를-만들고-링크하여-컴파일-하기
정적(Static) 라이브러리 만들기
1. 메뉴[New] -> [C++ Project] 선택
[Project name] : testlib [입력]
[Project type] : Static Library -> Empty Project [선택]
[Toolchains] : Cygwin GCC [선택]
버튼 [Finish] 선택
프로젝트 선택 -> [New] -> [Folder] 선택
[Folder Name] : inc [입력]
버튼 [Finish] 선택
아래 그림과 같이 폴더 구조와 파일을 생성
testlib.h
/* * testlib.h * * Created on: 2012. 9. 6. * Author: bluexmas */ #ifndef LIBTEST_H_ #define LIBTEST_H_ extern const char* get_version(); #endif /* LIBTEST_H_ */
testlib.cpp
/* * testlib.cpp * * Created on: 2012. 9. 6. * Author: bluexmas */ #include "testlib.h" const char* get_version() { return "testlib ver 0.1"; }
inclue 폴더 설정
프로젝트 선택 -> [Properties] 선택
[C/C++ Build] -> [Settings] -> [Cygwin C++ Compiler] -> [Includes] - 버튼 [Add] 선택
버튼 [Workspace...] 선택
[testlib] -> [inc] 폴더 선택
버튼 [OK] 선택
추가된 Include 폴더 확인
키 [Ctrl] + [B] 선택하여 컴파일하고, [Debug] 폴더 밑에 libtestlib.a 확인
정적 라이브러리 사용하기
1. 메뉴[New] -> [C++ Project] 선택
[Project name] : testlib_sample [입력]
[Project type] : Executable -> Empty Project [선택]
[Toolchains] : Cygwin GCC [선택]
버튼 [Finish] 선택
testlib_sample.cpp 파일
#include#include "testlib.h" int main(int argc, char **argv) { fprintf(stdout, "%s", get_version()); return 0; }
inclue 폴더 설정
Libraries 추가
Library search path 추가
키 [Ctrl] + [B] 선택하여 컴파일
실행해서 확인하기
실행결과