linux下 动态链接库的制作

keil 分散加载 动态_C语言学习篇(31)——linux中制作动态链接库 引言前面我们讲解了什么是函数库(函数库就是一些事先写好的函数集合),函数库有什么作用(可以打包我们的编写的源代码,供他人使用,同时源码不可见,保护了自己的知识产权)以及函数库有2种提供方式:静态链接库和动态链接库,前面2篇分别讲解了如何在linux中使用gcc工具链和windows中keill armcc工具链制作我们静态链接库,今天我们继续来说说如何在linux gcc制作动态链接库。为什么不在... 阅读详情

linux下动态链接库的制作:

so可以供多个进程使用,不同进程调用同一个so文件,

so文件源程序不需要main函数,有也不会被执行。

下面通过一个简单例子,来学习.so文件的制作跟使用。

/* 
 * max.h 
 * 
 */  
  
/*条件编译*/  
#ifndef MAX_H_  
#define MAX_H_  
  
#ifdef __cpluscplus  
extern "C"{  
#endif  
   int max(int a,int b);  
#endif /* MAX_H_ */  

/* 
 * max.cpp
 * 
*/
#include "max.h"
int max(int a,int b)  
{  
    return a>b?a:b;  
}  

链接库的制作:

编译c程序:
gcc -shared -fpic XXX.c -o XXX.so

编译c++程序:
g++ -shared -fpic XXX.cpp -o XXX.so

/* 
 * main.cpp 
 * 
 */  
#include <stdio.h>  
#include "max.h"  
int main(void)  
{  
    printf("call max function results is: %d\n",max(20,12));  
    return 0;  
}  
/* 使用libmax.so库 
 * gcc -o  main main.c -L. -lmax 
 * 
 *-L.: 在当前路径下寻找.so文件 
 *-lmax: 要链接这个libmax.so文件 
 * 
 * */  

编译main.cpp

       g++ -o main main.cpp -lmax

此时需要注意的是应该把libmax.so 放到/usr/lib目录中否则会出现错误

error while loading shared libraries: libmax.so: cannot open shared object file: No such file or directory

      ./main 结果出现20说明动态链接库制作正确。

如果要是在QT中调用,需要加上头文件和.so文件的绝对路径

INCLUDEPATH + =" "
LIBS += ""


$ g++ hello.cpp  -fPIC -shared -o libhello.so

$ g++ main.cpp -L. -lhello -o main

交叉编译步骤一致:

(1)  $arm-linux-g++ hello.cpp -fPIC -shared -o libarmhello.so

(2)  $arm-linux-g++ main.cpp -L. -larmhello -o armhello

交叉编译的时候出现错误:fatal error:opencv2/imgproc/imgproc.hpp:no such file or directory

解决方法:把交叉编译好的opencv下的include中的opencv2拷贝到交叉编译器中的include下

我的交叉编译好的opencv和opencv2路径是在:/opt/arm/include  

把/opt/arm/include  文件下的opencv2 复制到/opt/fsl-linaro-toolchain/arm-fsl-linux-gnueabi/include即可。


在linux下制作静态库和动态链接库的方法 静态库 .o文件的集合 制作 ar -cr libxxx.a xxx1.o xxx2.o xxx3.o ... 编译 gcc main.c -l xxx [-L 库路径] (如果不加-L则在标准库路径下查找) 运行 ./a.out 基本概念: 静态库又称为文档文件(Archive File)。它是多个.o文件的集合。Linux中静态库文件的后缀为"a"。 静态库的代码在 阅读详情

相关推荐

EPLAN Electric P8 2025安装避坑指南:硬件、.NET 6与VM配置全解析

EPLAN Electric P8 是面向工业自动化电气设计的工程级CAD平台,其核心依赖于.NET运行时、DirectX硬件加速与本地许可证验证机制。随着2025版升级至.NET 6.0 Runtime、DirectX 12渲染引擎及双模授权校验,安装失败率显著上升——尤其在显卡驱动陈旧、虚拟机环境或企业离线场景下。技术价值在于保障PLC柜体布局、端子排自动生成、电缆清册输出等产线级功能稳定运行;典型应用场景包括高校电赛控制系统设计、包装线电控图纸交付及集成商多版本协同部署。本文聚焦EPLAN 2025安

weixin_30897079的博客 583

Linux-(C/C++)动态链接库生成以及使用(libxxx.so)

Linux中so文件为共享库,与windows下dll类似,不过实现要简单。 so可以供多个进程使用,不同进程调用同一个so文件,所使用so文件不同。 so文件源程序不需要main函数,有也不会被执行。 下面通过一个简单例子,来学习.so文件的制作跟使用(前提已经配置好环境)、 主要了解学习用C语言编译一个动态链接库,如何使用这个库 1、通过简单max函数,生成一个l

Commander 4417

龙头复盘神器/复盘于导出工具最新版5.6

龙头复盘神器,复盘于导出工具

初入python踩过的坑 8280

Linux之动态链接库

动态链接库正确的名字叫共享库,英文 Shared Library。在windows下表现为 文件,在linux下表现为 文件。之所以叫共享库,是因为多个独立的程序可以共同使用同一个共享库,达到减少执行文件的大小,直到运行时才动态加载,节省磁盘空间和内存空间。下面通过一个案例深入了解动态库的使用。main.cpp 用来生成可执行程序。 该程序依赖于一个random库,库的源码如下: 现在,我们用clang++编译器编译这个程序。(clang++与g++类似,但更适合于开发,可以sudo apt inst

FlyWine的博客 2914

大模型应用开发面试全流程实录:RAG、上下文工程与多Agent协作技术深度解析

Transformer 依靠多头自注意力和位置编码实现高效序列建模。Prompt Engineering包含多种设计思路,如 Zero-shot、Few-shot、Chain-of-thought,提升模型泛化和推理。Token 和上下文窗口直接影响模型性能与成本,选择需结合实际业务场景(如客服对话需长窗口)。Embedding 技术是 RAG 的基础,决定了语义检索效果。向量数据库如 FAISS、Milvus等分别适用于本地/分布式检索。

m0_52114506的博客 839

【嵌入式Linux】EC20模块多运营商自适应PPP拨号实战:从IMSI识别到网络配置

本文详细介绍了在嵌入式Linux系统中,如何基于EC20 4G模块实现多运营商自适应PPP拨号。通过解析SIM卡的IMSI识别运营商,并动态配置对应的APN和拨号参数,结合AT指令交互与健壮的pppd脚本,解决了设备跨地域部署时的网络自动连接问题,提升了物联网设备的部署效率和稳定性。

fox11的博客 914

Linux动态链接库

··· Linux下动态链接库(.so) 类比于windows下的dll,动态链接库特点是:不参与编译,只在程序运行时调用至内存。 注意:so一定要以lib开头,比如编译为:lib_xxxx.so,则调用时为:-l_xxxx(小写L,去掉lib头和so尾) 1.1 创建so 将./lib/src文件夹下的liba.c libb.c 文件编译成so: $ gcc a.c liba.c libb.c -fPIC -shared -o lib_my.so 其中:-shared 指定生成动态链接库

hanxuan12233的博客 3203

R语言机器学习:XGBoost线性回归模型的SHAP值

SHAP(SHapley Additive exPlanations)值是一种基于博弈论Shapley值的机器学习模型解释方法,能够解释任何模型的预测结果。其主要用途包括:1)提高模型的可解释性,帮助非技术用户理解模型预测;2)识别对模型预测最重要的特征,辅助特征选择;3)调试模型,发现预测中的异常;4)评估模型公平性,避免偏见。SHAP值的计算方法包括初始化、迭代计算、归一化和解释,常用工具如Python的shap库支持多种计算方式(如TreeSHAP、KernelSHAP等)。本文还提供了基于R语言计算

专注生信领域 3452

【Linux系统编程】Linux动态库详解

所谓“程序库”,简单说,就是包含了数据和执行码的文件。其不能单独执行,可以作为其它执行程序的一部分来完成某些功能。库的存在可以使得程序模块化,可以加快程序的再编译,可以实现代码重用,可以使得程序便于升级。程序库可分静态库(static library)和共享库(shared library)。不管是Linux还是Windows中的库文件其本质和工作模式都是相同的, 只不过在不同的平台上库对应的文件格式和文件后缀不同。程序中调用的库有两种静态库和动态库。

C/C++软件工程师、嵌入式软件工程师、物联网研发工程师、C/C++讲师、物联网讲师、嵌入式讲师、鸿蒙讲师---欢迎大家一起交流(私信添加博主微信) 3692

Quartus II编译时出现Error (119013): Current license file does not support the EP4CE6E22C6 device

Quartus II编译时出现Error (119013): Current license file does not support the EP4CE6E22C6 device, Quartus的安装过程不同于ISE/vivado的安装。“Current license file does not support”这种情况多出现在高版本的quartus中综合很久以前的代码,使用很早型号的FPGA或是CPLD。对于这种情况,就得在官网或是其他网站上下载包含所需Device的库文件。

夜半少年的博客 1万+

第10集:AIOps 平台架构设计!画出面试官最想看的系统全景图

本文介绍了如何将AIOps平台的六大功能模块整合为四层架构设计,并生成专业系统全景图。文章首先指出面试中架构设计能力的重要性,强调一张清晰的架构图能直观展现全局观。随后指导读者检查项目结构,准备绘图环境。核心部分详细拆解了四层架构:数据采集层(Prometheus、ELK等)、AI分析层(巡检、告警、预测等)、决策执行层(工作流引擎、自愈Agent)和展示交互层(API、控制台)。通过Python代码自动生成模块依赖关系图,并提供了面试讲解技巧。全文旨在帮助开发者在面试中系统性地展示项目架构设计能力。

qq_2937655951的博客 104

linux中c语言动态库编译,C语言学习篇(31)——linux中制作动态链接库

引言前面我们讲解了什么是函数库(函数库就是一些事先写好的函数集合),函数库有什么作用(可以打包我们的编写的源代码,供他人使用,同时源码不可见,保护了自己的知识产权)以及函数库有2种提供方式:静态链接库和动态链接库,前面2篇分别讲解了如何在linux中使用gcc工具链和windows中keill armcc工具链制作我们静态链接库,今天我们继续来说说如何在linux gcc制作动态链接库。为什么不在...

weixin_31523181的博客 513

手把手教你实现RK3588的Secure Boot:密钥烧录与镜像签名验证

摘要:本文详细介绍了瑞芯微RK3588平台下SecureBoot的密钥烧录与镜像签名验证实现方法。首先阐述了SecureBoot的工作原理、安全优势及其在RK3588智能安防、工业控制等场景中的重要作用。接着分步骤指导了硬件准备、软件工具配置、密钥对生成等准备工作,并详细说明了进入烧录模式、工具选择配置、密钥烧录执行等关键操作流程。文章还解析了镜像签名生成与验证机制,包括启动验证流程和常见故障处理方法。最后对SecureBoot在RK3588设备中的未来应用进行了展望,强调其与TrustZone等安全技术融

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 2052

keil 分散加载 动态_嵌入式C语言进阶之——linux中制作动态链接库

引言前面我们讲解了什么是函数库(函数库就是一些事先写好的函数集合),函数库有什么作用(可以打包我们的编写的源代码,供他人使用,同时源码不可见,保护了自己的知识产权)以及函数库有2种提供方式:静态链接库和动态链接库,前面2篇分别讲解了如何在linux中使用gcc工具链和windows中keill armcc工具链制作我们静态链接库,今天我们继续来说说如何在linux gcc制作动态链接库。为什么不在...

weixin_28987547的博客 741

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

linux 下动态链接库的制作与使用

linux 下动态链接库的制作与使用 动态链接库*.so的编译与使用- - 动态库*.so在linux下用c和c++编程时经常会碰到,最近在网站找了几篇文章介绍动态库的编译和链接,总算搞懂了这个之前一直不太了解得东东,这里做个笔记,也为其它正为动态库链接库而苦恼的兄弟们提供一点帮助。 1、动态库的编译 下面通过一个例子来介绍如何生成一个动态库。这里有一个头文件:so_test.h,三个.c

随便写写 7396

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

linux怎样自制库_linux 下动态链接库的制作与使用

linux 下动态链接库的制作与使用动态链接库*.so的编译与使用- -动态库*.so在linux下用c和c++编程时经常会碰到,最近在网站找了几篇文章介绍动态库的编译和链接,总算搞懂了这个之前一直不太了解得东东,这里做个笔记,也为其它正为动态库链接库而苦恼的兄弟们提供一点帮助。1、动态库的编译下面通过一个例子来介绍如何生成一个动态库。这里有一个头文件:so_test.h,三个.c文件:test_...

weixin_30371285的博客 184

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Linux制作动态链接库

1.什么是动态链接库动态链接库是程序运行时加载的库,当动态链接库正确安装后,所有的程序都可以使用动态库来运行程序。动态链接库是目标文件的集合,目标文件在动态链接库中的组织方式是按照特殊方式形成的。库中函数和变量的地址是相对地址,不是绝对地址,其真实地址在调用动态库的程序加载时形成。 动态链接库的名称有别名(soname),真名(realname)和链接名(linker name)。别名由一个前缀l

HP的博客 1759

如何在Linux上制作动态链接库

本文翻译自: How dynamic linking for modular libraries works on Linux 放到Ubuntu上试试行不行。 1.Linker 一个Linker是一种命令,将许多程序片段联系在一起,并且识别针对他们的内存分配。一个linker的功能包括: (1) 集成程序的所有部分 (2) 恢复内存,以至于程序能运行在新的内存组织下。 (3) 解析符号引用 (4) 建立新的内存组织以至于所有的程序能组织在一起。 2.创建对象文件 首先,创建头文件mymath.h: (关于如

weixin_43638873的博客 173

Linux动态链接库的制作

类似与 win下的dll文件,linux下动态链接库采用 lib+program_name+.so的形式命名动态链接库 动态链接库的作用是实现资源共享,各个进程可以同时使用这一段代码而不必在乎其是否正在被使用。 下面介绍动态链接库的生成方法。 头文件 socklib.h

钱国正的专栏 1940

linux 制作静态动态链接库

静态库和动态库的区别:.so动态库,.a静态库 头文件myprint.h #ifndef __MY_PRINT_ #define __MY_PRINT_ #include <stdio.h> void print(); #endif 源文件 myprint.cpp #include "myprint.h" void print() { printf("make...

qiukapi的博客 233
上一篇: C/C++常见gcc编译链接错误解决方法
下一篇: QT和VS读取.txt文件中的数据并保存为数组
lihuajie1003
博客等级 码龄12年 59粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值