static library sample

//static library project

lib.h

View Code
extern "C" int __cdecl Add(int, int);

 

lib.cpp

View Code
#include "lib.h"
int __cdecl Add(int a, int b)
{
    return a + b;
}

 

//App project

View Code
#include <stdio.h>

#include "..\\staticdll\\lib.h"
#pragma  comment(lib, "..\\debug\\staticlib.lib")


int main()
{
    printf("4 + 6 = %d\n", Add(4, 6));


    return 0;
}

代码中#pragma comment( lib , "..\\debug\\libTest.lib" )的意思是指本文件生成的.obj文件应与libTest.lib一起连接。

posted on 2013-02-25 00:15  All IN  阅读(130)  评论(0)    收藏  举报

导航