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一起连接。

浙公网安备 33010602011771号