一、gcc生成静态库与动态库
本文主要讲解在Ubuntu系统下使用gcc命令来生成静态库.a与动态库.so以及在程序中使用静态库和动态库
(一)、生成静态库
(1)首先先创建一个作业目录test1用来保存本次作业
mkdir test1
切换目录cd test1
-
编写子程序hello.h
#ifndef HELLO_H #define HELLO_H void hello(const char *name); #endif//HELLO_H
-
编写子程序hello.c
#include<stdio.h> void hello(const char *name) { printf("Hello %s\n",name); }
-
编写子程序main.c
#include"hello.h" int main() { hello("everyone"); return 0; }
(2)运用gcc生成.o文件
gcc -c hello.c