现在的位置: 首页 > 综合 > 正文

linux下静态库使用

2013年10月09日 ⁄ 综合 ⁄ 共 375字 ⁄ 字号 评论关闭

//test.c

#include <stdio.h>

Test(void)

{ printf("Test ok...\n");}


//test.h

#ifndef _TEST_H

#define _TEST_H

void Test(void)

#endif//_TEST_H


//main.c

#include <stdio.h>

#include "test.h"

int main(int argc, char *argv[])

{

Test();

return 0;

}

生成静态库步骤:

1编译: gcc -o test.o test.c

2生成库文件: ar - ./ libtest.a test.o

3使用:

#makefile

main: main.o

         gcc -o $@ -L./ $< -lTest

main.o: main.c

        gcc -I./ -o $@ -c $<

clean:

         rm *.o main

抱歉!评论已关闭.