gcc shared object
介绍一个生成动态链接库*.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的更多相关文章
- 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 ...
- 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_ ...
- 运行编译后的程序报错 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 ...
- 动态链接库找不到 : 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 ...
- libstdc++.so.5: cannot open shared object file: No such file or directory
中文分词一般会选择ICTCLAS的模块,虽然不能说很完美,但也算是一个不错的选择.它提供了windows版本和linux版本,并支持C/C#/JNI接口.这本来是一个不错的事情,但版本一多,官方似乎就 ...
- 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 ...
- 〖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 ...
- 关于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也正常启动, ...
- 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 ...
随机推荐
- 使用BCP导出导入数据
bcp 实用工具可以在 Microsoft SQL Server 实例和用户指定格式的数据文件间大容量复制数据. 使用 bcp 实用工具可以将大量新行导入 SQL Server 表,或将表数据导出到数 ...
- 当你还在纠结于ORM的性能时,我已经远远的把你抛在脑后
最近找工作面试,问到一些过去的工作和项目经验.我把公司用到的ORM框架(LLBL Gen)拿出来谈一谈,说一下他的优势,对方却一直追问ORM的好处,性能方面的问题,让我有时候都不知道如何回答,产生了不 ...
- Android入门(五)UI-单位与尺寸、ListView
原文链接:http://www.orlion.ga/453/ 一.单位与尺寸 布局文件中一共有以下单位供选择:px,pt,dp,sp px:是像素,屏幕中可见的最小元素单位. pt:是磅,1磅等于1/ ...
- 什么才是正确的javascript数组检测方式
前面的话 对于确定某个对象是不是数组,一直是数组的一个经典问题.本文专门将该问题择出来,介绍什么才是正确的javascript数组检测方式 typeof 首先,使用最常用的类型检测工具——typeof ...
- Packet for query is too large(1767212 > 1048576)mysql在存储图片时提示图片过大
原网址:http://blog.csdn.net/bigbird2012/article/details/6304417 错误现象:Packet for query is too large(1767 ...
- SQL*Loader之CASE4
CASE4 1. SQL脚本 [oracle@node3 ulcase]$ cat ulcase4.sql set termout off rem host write sys$output &quo ...
- tiltShift.js - CSS3 滤镜实现移轴镜头效果
tiltShift.js 是一款很棒的 jQuery 插件,使用 CSS3 图片滤镜来实现照片的移轴镜头效果.使用非常简单,使用 data 属性配置参数.温馨提示:为保证最佳的效果,请在 IE10+. ...
- jQuery.Deferred 源码分析
作者:禅楼望月(http://www.cnblogs.com/yaoyinglong ) 1 引子 观察者模式是我们日常开发中经常用的模式.这个模式由两个主要部分组成:发布者和观察者.通过观察者模式, ...
- Android Fragment完全解析
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8881711 我们都知道,Android上的界面展示都是通过Activity实现的, ...
- 对比MFC资源文件谈谈WPF布局方式
对比MFC资源文件谈谈WPF布局方式 MFC方式 对于传统的MFC基于UI的应用程序设计通常分两步走,首先是设计UI,使用的是RC文件,然后是代码文件,对RC文件进行操作,如下面Figure 1 的基 ...