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 ...
随机推荐
- SQL Server中一个隐性的IO性能杀手-Forwarded record
简介 最近在一个客户那里注意到一个计数器很高(Forwarded Records/Sec),伴随着间歇性的磁盘等待队列的波动.本篇文章分享什么是forwarded record,并从原理上谈一 ...
- javascript学习总结(一):基础知识。
1 数据类型a.数据类型共有7种,字符串(string).数字(number).布尔(boolean).数组(array).对象(object).Null.Undefined. 其中布尔(逻辑)类型只 ...
- HTML&CSS学习总结(一)
上周用了一周的时间,周一到周五平均每天2-3小时,周六.周日每天各8小时,看网易云课堂燕十八的HTML+div+CSS视频,感觉还不错,按照视频的讲课思路大概做个总结吧. 基本思路:从大的方面(整体结 ...
- 创建支持多种屏幕尺寸的Android应用
Android涉及各种各样的支持不同屏幕尺寸和密度的设备.对于应用程序,Android系统通过设备和句柄提供了统一的开发环境,大部分工作是校正每一个应用程序的用户界面到它显示的屏上.与此同时,系统提供 ...
- 使用NuGet管理项目类库引用
NuGet 是微软开发平台(包括.NET平台)的一个包管理器,这里只介绍和.NET相关的NuGet Visual Studio扩展客户端, 在VS2010 ,VS2012 ,VS2013中默认集成了N ...
- Windows Azure Web Site (9) Web Site公网IP地址
<Windows Azure Platform 系列文章目录> 本文会同时介绍国内由世纪互联运维的Azure China和海外Azure Global. 熟悉Windows Azure平台 ...
- CentOS7 SonarQube安装
CentOS7 SonarQube安装 CentOS7 SonarQube安装 Download 从sonarqube下载sonarqube-5.0.zip 从sonarqube下载sonar-run ...
- Halcon与MFC交互编程
Halcon是商业化的机器视觉软件.网上下了halcon10的破解版,安装后编写了个图像显示的MFC小程序. 编译器用的是VS2008. 1 配置halcon环境 新建为MFC后,在VC++目录中配置 ...
- Git undo 操作
相比传统的版本管理工具,git 的 undo 操作也不是很简单明了,本文尝试总结常用的 undo 操作. 重新提交 应该避免考虑不周全的提交,但这太难了.因此Git 专门提供了一个命令来弥补粗心的提交 ...
- C语言编译过程
GCC编译C源码有四个步骤: 预处理-----> 编译 ----> 汇编 ----> 链接 一. 编译和链接的流程 C语言的编译链接过程要把我们编写的一个c程序(源代码)转换成可以在 ...