介绍一个生成动态链接库*.so的例子: 首先新建1个头文件test.h:

#include <stdio.h>
void first();
void second();
void third();

然后新建3个源文件first.c/second.c/third.c:

first.c:

#include "test.h"
void first() {
    printf("this is first.\n");
}

second.c:

#include "test.h"
void second() {
    printf("this is second.\n");
}

third.c:

#include "test.h"
void third() {
    printf("this is third.\n");
}

然后,生成动态链接库libtest.so: gcc first.c second.c third.c -fPIC -shared -o libtest.so 
说明:1、-fPIC意思是代码位置独立便于程序共享。2、-shared意思是生成动态链接库

接着新建一个调用动态链接库的源代码test.c:

#include "test.h"
void main(){
    first();
    second();
    third();
}

跟着生成可执行文件: gcc test.c -L. -ltest -o test 
说明:-L.表示链接库在当前目录;-ltest表示根据隐含规则查找到libtest.so的链接库

此时执行./test会得到如下结果:

this is first.
this is second.
this is third.

如果没有得到这个结果,而是提示你“./test: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory ”,那么就在/etc/ld.so.conf.d目录下新建一个test.conf配置文件,并在该文件中写入你的动态链接库的访问路径比如/usr/local/demo/lib,具体根据自己的情况而定。建好之后键入sudo ldconfig使配置生效。

over.

ps: 
对于找不到链接库的情况,还可以通过创建软链接的方式,比如ln -s /your_folder/*so /usr/lib

gcc shared object的更多相关文章

  1. gcc编译参数-fPIC问题 `a local symbol' can not be used when making a shared object;

    gcc -shared -o hack.so hack.c/usr/bin/ld: /tmp/ccUZREwA.o: relocation R_X86_64_32 against `a local s ...

  2. gcc报错 can not be used when making a shared object; recompile with -fPIC

    使用google protobuf时,出现错误 /usr/bin/ld: /usr/local/lib/libprotobuf.a(message_lite.o): relocation R_X86_ ...

  3. 运行编译后的程序报错 error while loading shared libraries: lib*.so: cannot open shared object file: No such file or directory

    运行编译后的程序报错  error while loading shared libraries: lib*.so: cannot open shared object file: No such f ...

  4. 动态链接库找不到 : error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory

    问题: 运行gsl(GNU scientific Library)的函数库,用 gcc erf.c -I/usr/local/include -L/usr/local/lib64 -L/usr/loc ...

  5. libstdc++.so.5: cannot open shared object file: No such file or directory

    中文分词一般会选择ICTCLAS的模块,虽然不能说很完美,但也算是一个不错的选择.它提供了windows版本和linux版本,并支持C/C#/JNI接口.这本来是一个不错的事情,但版本一多,官方似乎就 ...

  6. libssl.so.10: cannot open shared object file: No such file or directory

    今天在使用yum安装东西的时候报错 yum list There was a problem importing one of the Python modulesrequired to run yu ...

  7. 〖Android〗arm-linux-androideabi-gdb报 libpython2.6.so.1.0: cannot open shared object file错误的解决方法

    执行: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gdb out/target/p ...

  8. 关于ImportError: libssl.so.10: cannot open shared object file: No such file or directory unable to load app 0 (mountpoint='') (callable not found or import error)

    一.问题描述 在亚马逊云服务器使用Nginx+uwsgi部署django项目时,项目可以使用python manage.py runserver正常运行,uwsgi测试也没问题,Nginx也正常启动, ...

  9. rpm: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory解决办法

    不多说,直接上干货! 问题详情 [root@bigdatamaster app]# rpm -qa | grep gcc rpm: error : cannot open shared object ...

随机推荐

  1. QTP11的下载地址和破解教程

    qtp11 下载地址 http://pan.baidu.com/s/1rE3l6 qtp10的破解 下载注册机http://ishare.iask.sina.com.cn/f/20991520.htm ...

  2. JQuery uploadify 的使用

    在Java WEB项目中用到了上传图片的功能,于是百度了一下,发现 uploadify 的出镜率很高,于是决定使用这个插件.结果昨天调试了一天没有成功,今天早上仔细想了想,觉得应该是调用js文件的原因 ...

  3. CSS计数器

    使用CSS计数器就像使用变量一样. 它有以下几个属性: counter-reset 创建或重置计数器 counter-increment 增长计数器 content 生成内容 counter() 将计 ...

  4. ELCImagePickerController 的集成

    1,  将文件夹ELCImagePicker拷贝到工程中 2,添加系统库AssetsLibrary.framework 3,  添加系统库MobileCoreServices 4,在头文件中加入引用# ...

  5. Android引导页设计

    大家在安装好一个应用后,第一次打开时往往会出现一个使用引导页,形式一般为三.四张图片,随着我们的滑动进行切换,在最后一页会有一个进入应用的按钮,我们通过点击这个按钮可以进入应用,其实这其中没有太多的复 ...

  6. Android基于mAppWidget实现手绘地图(十五)–如何控制放大缩小

    一般来说,可以使用以下几种方式来控制地图的放大/缩小 : 1. 使用控件底部的缩放按钮 2.双击控件 3.pinch手势 4.物理按键 :I键标识缩小  :O键表示放大.(只有设备具有物理按键才行) ...

  7. Windows Azure Web Site (1) 用户手册

    <Windows Azure Platform 系列文章目录> 下载地址: Web Apps用户手册

  8. Microsoft Azure News(5) Azure新DV2系列虚拟机上线

    <Windows Azure Platform 系列文章目录> 在之前的文章中,笔者了Azure VM虚拟机,分为A系列和D系列2种 Microsoft Azure News(4) Azu ...

  9. BufferHelp byte[] Stream string FileStream Image Bitmap

    /******* * *** ***** ** ** * * * * * * * * ***** * * * * * * * * * * * * * * * ******* *** * ***** * ...

  10. C#实现网页爬虫

    HTTP请求工具类(功能:1.获取网页html:2.下载网络图片:): using System; using System.Collections.Generic; using System.Dra ...