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 ...
随机推荐
- WPF入门教程系列五——Window 介绍
一.窗体类基本概念 对于WPF应用程序,在Visual Studio和Expression Blend中,自定义的窗体均继承System.Windows.Window类.用户通过窗口与 Windows ...
- 阿里云上安装mysql步骤/ 阿里云ECS搭建Java+mysql+tomcat环境
使用阿里云ECS挺长一段时间了.这两天碰巧朋友小白让我一步一步教他在ECS上搭建Java+mysql+tomcat环境,所以把在这里把步骤在这简单整理了一下,以便需要的人查阅. 我购买的阿里云服务器系 ...
- Java EE开发平台随手记6——Mybatis扩展4
这篇博客中来说一下对Mybatis动态代理接口方式的扩展,对于Mybatis动态代理接口不熟悉的朋友,可以参考前一篇博客,或者研读Mybatis源码. 扩展11:动态代理接口扩展 我们知道,真正在My ...
- NYOJ995硬币找零(简单dp)
/* 题意:给你不同面额的硬币(每种硬币无限多),需要找零的面值是T,用这些硬币进行找零, 如果T恰好能被找零,输出最少需要的硬币的数目!否则请输出剩下钱数最少的找零方案中的最少硬币数! 思路:转换成 ...
- Effeckt.css – CSS3 Transitions & Animations 精妙应用
CSS3 不仅仅用作界面效果补充,还可以用来替换传统的一些界面实现,而且效果更酷.Effeckt.css 收集了众多精妙的 CSS3 Transitions & Animations 效果应用 ...
- [SDK2.2]Windows Azure Cloud Service (35) 使用VS2013发布Azure Cloud Service
<Windows Azure Platform 系列文章目录> 好久没有更新BLOG了,今天我们继续Windows Azure相关的内容. 笔者最近把Visual Studio升级到了20 ...
- [New Portal]Windows Azure Virtual Machine (22) 使用Azure PowerShell,设置Virtual Machine Endpoint
<Windows Azure Platform 系列文章目录> 我们可以通过Windows Azure Management Portal,打开Virtual Machine的Endpoi ...
- 22套精致的用户界面 PSD 源文件素材《免费下载》
在这里,我们给大家分享一组精美的 PSD 源文件素材,可以免费下载使用.PSD 素材是很好的资源,对于每个设计师都非常有用,这是设计师之所以不断发布新的和有用的 PSD 文件的原因.高品质的 PSD ...
- 关于WEB Service&WCF&WebApi实现身份验证之WEB Service篇
在这个WEB API横行的时代,讲WEB Service技术却实显得有些过时了,过时的技术并不代表无用武之地,有些地方也还是可以继续用他的,我之所以会讲解WEB Service,源于我最近面试时被问到 ...
- js jquery 异常
1.0 TypeError: $(...).carousel is not a function原因:可能是没有引用或者引用了多个jquery:<script src="~/js/jq ...