介绍一个生成动态链接库*.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. Python中的运算符

    说完常用的数据类型,再来说下运算符.运算符用于将各种类型的数据进行运算,让静态的数据跑起来. 编程语言中的运算大致分为以下几个大类: 算术运算, 用于加减乘除等数学运算 赋值运算,用于接收运算符或方法 ...

  2. AJAX文件上传实践与分析,带HTML5文件上传API。

    对于HTML5已经支持AJAX文件上传了,但如果需要兼容的话还是得用一点小技巧的,HTML5等等介绍,先来看看以前我们是怎么写的. 网上可能会有一些叫AJAX文件上传插件,但在AJAX2.0之前是不可 ...

  3. Ubuntu-安装-theano+caffe-超详细教程

    一.说明 本文是继<Ubuntu-安装-cuda7.0-单显卡-超详细教程> 之后的续篇.theano和caffe是深度学习库,对运算能力需求很大,最好使用cuda进行加速.所以,请先阅读 ...

  4. Java多线程系列--“基础篇”11之 生产消费者问题

    概要 本章,会对“生产/消费者问题”进行讨论.涉及到的内容包括:1. 生产/消费者模型2. 生产/消费者实现 转载请注明出处:http://www.cnblogs.com/skywang12345/p ...

  5. [转载]UML时序图总结

    前言 在我的工作中,用的最多的就是时序图了.可能由于工作的原因,我也是最喜欢画时序图了,很清楚,很明了,什么时候发送什么消息,到达什么状态,一下子就展示在你的脑海里,对于消息驱动的程序来说,是再好不过 ...

  6. selenium处理select标签的下拉框

    有时候我们会碰到<select></select>标签的下拉框.直接点击下拉框中的选项不一定可行.Selenium专门提供了Select类来处理下拉框. <select  ...

  7. 关于Unicode和URL encoding入门的一切以及注意事项

    本文同时也发表在我另一篇独立博客 <关于Unicode和URL encoding入门的一切以及注意事项>(管理员请注意!这两个都是我自己的原创博客!不要踢出首页!不是转载!已经误会三次了! ...

  8. Theano入门神经网络(一)

    Theano是一个Python库,专门用于定义.优化.求值数学表达式,效率高,适用于多维数组.特别适合做机器学习.一般来说,使用时需要安装python和numpy. 首先回顾一下机器学习的东西,定义一 ...

  9. 需要正确安装 Microsoft.Windows.ShellExperienceHost 和 "Microsoft.Windows.Cortana" 应用程序。

    windows 10 开始菜单修复工具 Win10开始菜单修复工具出现的原因,自从升级到Windows  10,一直BUG不断,而其中有一个BUG非常的让你印象深刻,就是开始菜单无响应,你用着用着电脑 ...

  10. Oracle导入导出命令

    //导出 exp techrpt_data/techrpt_data@orcl file=d:\_临时文件\techrpt_data.dmp owner=techrpt_data //导入 imp t ...