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 ...
随机推荐
- Ionic 入门
什么是lonic 简单来说lonic就是一款HTML5移动端应用开发框架,通过配合AngularJS和Cordova/PhoneGap可以开发一款移动端app,值得注意的是它创建的app是混合移动应用 ...
- 微信5.0之Fragment使用
相信大家对于微信5.0的切换效果一定很有印象,对于一些童鞋一定认为这是通过TabHost实现的,不过这里我要纠正一下你们的错误观点了,这个效果的实现是通过Fragment+ViewPage实现的,看上 ...
- PHP的学习--解析URL
PHP中有两个方法可以用来解析URL,分别是parse_url和parse_str. parse_url 解析 URL,返回其组成部分 mixed parse_url ( string $url [, ...
- c#文本控件实现换行
要让一个Windows Form的C# TextBox换行显示多行文本就得把它的Multiline属性设置为true. 这个大家都知道,可是当你要在代码中为Text属性设置多行文本的时候可能会遇到点麻 ...
- [转载]TFS入门指南
[原文发表地址] Tutorial: Getting Started with TFS in VS2010 [原文发表时间] Wednesday, October 21, 2009 1:00 PM 本 ...
- Python编码问题整理
认识常见编码 GB2312是中国规定的汉字编码,也可以说是简体中文的字符集编码 GBK 是 GB2312的扩展 ,除了兼容GB2312外,它还能显示繁体中文,还有日文的假名 cp936:中文本地系统是 ...
- PyQt写的五子棋
技术路线 GUI的实现 使用PyQt技术作为基础.PyQt是一个支持多平台的客户端开发SDK,使用它实现的客户端可以运行在目前几乎所有主流平台之上. 使用PyQt,Qt设计器实现UI,通过pyuic4 ...
- VS2012 JSON、XML自动生成对应的类
在VS编辑下拉框中,选择选择性粘贴(Paste Special)
- 【原创】验证代理IP是否有用
/// <summary> /// 验证代理IP是否有用 /// </summary> /// <param name="ip">IP地址< ...
- 装饰者模式(Decorator pattern)
知识点 类应该对扩展开放,对修改封闭. 案例 (本故事纯属虚构) 某日早上,流年刚把新开发的游戏项目提交给经理 public abstract class Role { public virtual ...