the creating,installing and using of shared library
2011-08-19 12:59
519 查看
1 to create some .c file and .h file, for example, we create four .c file and one .h file.
/*a.c file*/
#include<stdio.h>
void function_test1(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*b.c file*/
#include<stdio.h>
void function_test2(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*c.c file*/
#include<stdio.h>
void function_test3(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*abc.h file*/
#include <stdio.h>
void function_test1(void);
void function_test2(void);
void function_test3(void);
/*main.c file*/
#include<stdio.h>
#include"abc.h"
int main(void)
{
function_test1();
function_test2();
function_test3();
return 0;
}
2 create library object files and shared librarygcc -fPIC -Wall -g -c a.c b.c c.c /*to create object file*/
gcc -g -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.1 a.o b.o c.o -lc /*to create shared library*/
3 set up the soname and linker nameln -sf libtest.so.1.0.1 libtest.so.1 /*set up the soname*/
ln -sf libtest.so.1 libtest.so /*set up the linker name*/
4 figure out the path of shared library
copy the library libtest.so.1.0.1, libtest.so.1,libtest.so to /usr/local/libthen
use the ldconfig to figure out the path /sbin/ldconfig -n
5 compile the file main.c which use the shared library
gcc -Wall -g -c main.c -o main.o
gcc -g -o main main.o -L. -ltest
if you want put the shared libarary in a temp dir: home/hero/program/libdir, use the following link option:
gcc -g -o main main.o -L /home/hero/program/libdir -ltest
6 Execute the program main
./main
/*a.c file*/
#include<stdio.h>
void function_test1(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*b.c file*/
#include<stdio.h>
void function_test2(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*c.c file*/
#include<stdio.h>
void function_test3(void)
{
printf("hello, this is [%s]\n", __FUNCTION__);
return;
}
/*abc.h file*/
#include <stdio.h>
void function_test1(void);
void function_test2(void);
void function_test3(void);
/*main.c file*/
#include<stdio.h>
#include"abc.h"
int main(void)
{
function_test1();
function_test2();
function_test3();
return 0;
}
2 create library object files and shared librarygcc -fPIC -Wall -g -c a.c b.c c.c /*to create object file*/
gcc -g -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0.1 a.o b.o c.o -lc /*to create shared library*/
3 set up the soname and linker nameln -sf libtest.so.1.0.1 libtest.so.1 /*set up the soname*/
ln -sf libtest.so.1 libtest.so /*set up the linker name*/
4 figure out the path of shared library
copy the library libtest.so.1.0.1, libtest.so.1,libtest.so to /usr/local/libthen
use the ldconfig to figure out the path /sbin/ldconfig -n
5 compile the file main.c which use the shared library
gcc -Wall -g -c main.c -o main.o
gcc -g -o main main.o -L. -ltest
if you want put the shared libarary in a temp dir: home/hero/program/libdir, use the following link option:
gcc -g -o main main.o -L /home/hero/program/libdir -ltest
6 Execute the program main
./main
相关文章推荐
- Issue 71 - pymssql - Undefined symbols on Mac, CentOS, Redhat with pre-compiled build - A fast MS SQL Server client library for Python directly using C API instead of ODBC. It is Python DB-API 2.0 compliant. Works on Linux, *BSD, Solaris, Mac OS X and Win
- An Example of Pre-Query and Post-Query Triggers in Oracle Forms With Using Display_Item to Highlight Dynamically
- The ins and outs of using Java with Domino
- 93.View the Exhibit and examine the structure of the CUSTOMERS table. Using the CUSTOMERS table, y o
- Start your own JavaScript library using webpack and ES6
- 【转载】Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report
- Walkthrough: Creating and Using a Dynamic Link Library (C++)
- Tips: 使用autotools生成动态.so库文件 / Generate .so library files using autotools in Solaris and Linux
- Creating and Using a Dynamic Link Library
- How to get Full Rom Dump / Stock ROM of MT6572 MediaTek Smartphones using SPFT and MTK Droid Root an
- Installing mysql on windows 7 and using ruby on it
- Using the multiple NICs of your File Server running Windows Server 2008 (and 2008 R2)
- XMPPError: bad-request - modify error create new user using smack library 4.1.4 and openfire
- My Fluid Simulation (SPH) Sample (3) – Optical Effects using GLSL, and Integration of Physical Model
- Creating a shared and static library with the gnu compiler [gcc]
- 图(有向图,无向图)的邻接矩阵表示C++实现(遍历,拓扑排序,最短路径,最小生成树) Implement of digraph and undigraph using adjacency matrix
- MS Bigdata HDInsight -Process, analyze, and gain new insights from big data using the power of Apache Hadoop
- On Using SQLite and FMDB Instead of Core Data
- Human detection using oriented histograms of flow and appearance中的实验方法