ar description

ar is considered a binary utility because archives of this sort are most often used as libraries holding commonly needed subroutines.

Linux Library Types:

There are two library types which can be created:

1. Static libraries (.a): Library of object code which is linked with, and becomes part of the application.
2. Dynamically linked shared object libraries (.so): There is only one form of this library but it can be used in two ways.
1. Dynamically linked at run time but statically aware. The libraries must be available during compile/link phase. The shared objects are not included into the executable component but are tied to the execution.
2. Dynamically loaded/unloaded and linked during execution (i.e. browser plug-in) using the dynamic linking loader system functions.

[b]Library naming conventions:[/b]
Libraries are typically names with the prefix "lib". This is true for all the C standard libraries. When linking, the command line reference to the library will not contain the library prefix or suffix.

Thus the following link command: gcc src-file.c -lm -lpthread
The libraries referenced in this example for inclusion during linking are the math library and the thread library. They are found in /usr/lib/libm.a and /usr/lib/libpthread.a.



void ctest1(int *i)
{
*i=5;
}

void ctest2(int *i)
{
*i=100;
}
#include <stdio.h>
void ctest1(int *);
void ctest2(int *);

int main()
{
int x;
ctest1(&x);
printf("Valx=%d\n",x);

return 0;
}


# Compile: cc -Wall -c ctest1.c ctest2.c
Compiler options:

* -Wall: include warnings. See man page for warnings specified.

# Create library "libctest.a": ar -cvq libctest.a ctest1.o ctest2.o
# List files in library: ar -t libctest.a
# Linking with the library:

* cc -o executable-name prog.c libctest.a
* cc -o executable-name prog.c -L/path/to/library-directory -lctest

gcc -o prog prog.c libctest.a
cc -o executable-name prog.c -L/path/to/library-directory -lctest

cc -o executable-name prog.c -L/home/hanyh/workspace/cplusplus/linux -lctest


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值