linux 下动态库、静态库嵌套使用
linux下静态库嵌套使用
前提是你会在linux下调用静态库和动态库和Makfile编程(当然不会Makfile直接在终端命令也成)
本例是先由StringLen.h,StringLen.c生成librak.a
然后利用StringLen2.h,StringLen2.并调用librak.a生成librak2.a
最后利用StringLen3.h,StringLen3.c调用librak2.a 生成librak3.so
--------------------------------------------------------------------------------------
#StringLen.h:
#ifndef _STRINGLEN_H__
#define _STRINGLEN_H__
int Strlen(char *pStr);
#endif
#StringLen.c:
#include<stdio.h>
#include<assert.h>
#include "StringLen.h"
int Strlen(char *pStr)
{
unsigned long ulLength;
assert(NULL != pStr);
ulLength = 0;
while(*pStr++)
{
ulLength++;
}
return ulLength;
}
gcc -Wall -c *.c
ar rc librak.a *.o
------------------------------------------------------------------------------------
#StringLen2.h:
#ifndef _STRINGLEN_H2__
#define _STRINGLEN_H2__
#ifdef __UDT
#include "StringLen.h"
#endif
int Strlen2(char *pStr);
#endif
#StringLen2.c:
#include<stdio.h>
#include<assert.h>
#include "StringLen2.h"
int Strlen2(char *pStr)
{
unsigned long ulLength;
#ifdef __UDT
ulLength = Strlen(pStr);
#else
ulLength = -1;
#endif
return ulLength;
}
gcc -Wall -c *.c -D__UDT
ar rc librak2.a *.o
------------------------------------------------------------------------------------
相关文档:
一.前言
Linux拥有丰富各种源代码资源,但是大部分代码在Windows平台情况是无法正常编译的。Windows平台根本无法直接利用这些源代码资源。如果想要使用完整的代码,就要做移植工作。因为C/C++ Library的不同和其他的一些原因,移植C/C++代码是一项困难的工作。本文将以一个实际的例子(Tar)来说明如何把Linux代码移植 ......
Linux I2C核心、总线与设备驱动
注:
在linux2.6.32版本中有这样的代码与注释:
struct i2c_driver {
unsigned int class;
/* Notifies the driver that a new bus has appeared or is about to be
* removed. You should avoid using this if y ......
第十二章 文件管理及Linux实现问与答
12.1 什么是文件?它包含哪些内容?有什么特点?
答:文件是信息的一种组织形式,是存储在外存上的具有标识名的一组相关信息集合。文件包含的内容有:源程序、二进制代码、文本文档、数据、表格、声音和图象等。
文件具有的特点如下:
① 文件具有保存性,它被存储在某种 ......
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NTP_SERVER "clock.via.net"
#define ......