Implicit linking
순수 C언어로만 구성해보자. 참고로 개발 도구는 다음과 같다.
(1) 컴파일러 : Intel Compiler 10.1.020
(2) 툴 : Visual Studio 2008 Team System 2008
1. DLL 파일
Visual Studio -> Console Program -> empty project
참고로 프로젝트명은 testDll 이다.
파일명은 testDll.c 로 하고 다음과 같이 적는다.
__declspec(dllexport) char *str = "THE TRUTH IS OUT THERE";
__declspec(dllexport) int adds(int a, int b);
int adds(int a, int b)
{
return a+b+10;
}
이렇게 소스 코드를 작성 후, 컴파일을 하자!
(순수 C언어로 컴파일 하기 위해 컴파일방법을 "C" 언어로만 하도록 바꾼다. 이는 Project->Properties->C/C++->Advanced
Compile as 메뉴에서 "Compile as C COde" 로 하자.)
그러면 testDll.dll 및 testDll.lib 파일이 나온다.
(참고로 컴파일시 Project->Properties->General->Configuration type 에서 Dynamic Library 로 바꿔 주어야 한다.)
2. Dll 을 사용하는 코드
testadd.c
#include
__declspec(dllimport!) int adds(int,int);
(만약, 위의 줄을 사용하고 싶지 않으면 adds 를 헤더파일이 declaration 하면 된다.)
int main(void)
{
printf("sum %d \n",adds(4,6));
return EXIT_SUCCESS;
}
위와 같은 코드로 코딩한다.
Project->Properties->Linker -> Input ->Additional Dependencies 칸에 testDll.lib 를 적어넣는다.
(물론, 이 testadd.c 코드가 있는 디렉토리에 앞서 1번에서 만든 testDll.lib 파일을 복사해 넣어야 오류없이 컴파일이 될 것이다.)