so-a--linux---静态--动态--链接库

本文介绍了一个使用C语言进行编程的简单实例,包括头文件、源文件、编译过程及最终执行程序的输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//main.c
#include "zxc.h"

int main()
{
	printfbnq();
	return 0;
}
//zxc.h

void printfbnq();

//zxc.c
#include <stdio.h>

void printfbnq()
{
	long str[56]={0,1};
	int i;
	for(i=2;i<56;i++)
	{
		str[i]=str[i-1]+str[i-2];
		if(33==i||44==i||55==i)
		{
			printf("%ld\n",str[i]);	
		}	
	}
}


//begin static lib

ubuntu@ubuntu:~/gcclearn/gcctest/a$ gcc -c zxc.c
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ls
main.c  zxc.c  zxc.h  zxc.o
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ar -rc libzxc.a zxc.o
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ls
libzxc.a  main.c  zxc.c  zxc.h  zxc.o
ubuntu@ubuntu:~/gcclearn/gcctest/a$ gcc -o main.o -c main.c 
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ls
libzxc.a  main.c  main.o  zxc.c  zxc.h  zxc.o

ubuntu@ubuntu:~/gcclearn/gcctest/a$ gcc -o  main.exe -L./ main.o -lzxc
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ls
libzxc.a  main.c  main.exe  main.o  zxc.c  zxc.h  zxc.o
ubuntu@ubuntu:~/gcclearn/gcctest/a$ ./main.exe 
3524578
701408733
2144908973

//end static lib

//begin not static lib 

ubuntu@ubuntu:~/gcclearn/gcctest/a$ cp main.c zxc.c zxc.h ../so/
ubuntu@ubuntu:~/gcclearn/gcctest/a$ cd ../so
ubuntu@ubuntu:~/gcclearn/gcctest/so$ ls
main.c  zxc.c  zxc.h
ubuntu@ubuntu:~/gcclearn/gcctest/so$ gcc -fpic -shared -o libzxc.so zxc.c
ubuntu@ubuntu:~/gcclearn/gcctest/so$ ls
libzxc.so  main.c  zxc.c  zxc.h
ubuntu@ubuntu:~/gcclearn/gcctest/so$ gcc -o main.exe -L./ main.c lzxc
gcc: lzxc: No such file or directory
ubuntu@ubuntu:~/gcclearn/gcctest/so$ sudo cp libzxc.so /lib/
[sudo] password for ubuntu: 
ubuntu@ubuntu:~/gcclearn/gcctest/so$ sudo ldconfig
ubuntu@ubuntu:~/gcclearn/gcctest/so$ gcc -o main.exe -L./ main.c lzxc
gcc: lzxc: No such file or directory
ubuntu@ubuntu:~/gcclearn/gcctest/so$ gcc -o main.exe -L./ main.c -lzxc
ubuntu@ubuntu:~/gcclearn/gcctest/so$ ls
libzxc.so  main.c  main.exe  zxc.c  zxc.h
ubuntu@ubuntu:~/gcclearn/gcctest/so$ ./main.exe 
3524578
701408733
2144908973

//end not static lib 

//cp to my D:

ubuntu@ubuntu:~$ cd gcclearn/
ubuntu@ubuntu:~/gcclearn$ ls
gcc_01.c  multifiles  gcctest
ubuntu@ubuntu:~/gcclearn$ 
ubuntu@ubuntu:~/gcclearn$ cp gcctest/a/libzxc.a gcctest/a/zxc.h gcctest/so/libzxc.so  /mnt/hgfs/gcctest/
ubuntu@ubuntu:~/gcclearn$ cd gcctest/




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值