Skip to content

Instantly share code, notes, and snippets.

@zodiac1111
Created August 22, 2014 05:40
Show Gist options
  • Save zodiac1111/a791c063e8e43a45fadd to your computer and use it in GitHub Desktop.
Save zodiac1111/a791c063e8e43a45fadd to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include "staticlib.h"
int main(void)
{
printf("静态库链接示例: %d\n",foo(41));
return 0;
}
.PHONY:all staticlib main clean
all: staticlib main
staticlib:
gcc -c staticlib.c -o staticlib.o
ar -r staticlib.a staticlib.o
main:
gcc main.c staticlib.a
clean:
rm -f *.a *.o a.out
#include "staticlib.h"
int foo(int a)
{
return ++a;
}
//filename: staticlib.h
//最简单的库函数演示头文件.
#ifndef STATICLIB_H
#define STATICLIB_H
int foo(int a);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment