How to Use the Dynamic Link Library in C++ Linux (C++调用Delphi写的.so文件)
The Dynamic Link Library (DLL) is stored separately from the target application and shared among different applications, compared to Static Library. The DLL is the file extension on Windows while on Linux, it is *.so (Shared Object).
The *.so/*.dll can be loaded right before the application starts or during the application’s runtime. On Windows, the Win32 API LoadLibrary is used while on Linux gcc compiler, the dlopen function is used.
CREATING *.SO ON WINDOWS
There are many ways and many languages to create a *.so on Linux e.g. You can write a C or C++ source code and compile it with the following command:
1 |
gcc -shared -o libhello.so -fPIC hello.c |
Example hello.c that exports the hello function:
1 |
int hello() {
|
Let’s do this slightly differently. In this post, we learn that you can now use Delphi to compile the source code into Linux 64-bit Server native code directly.. So, let’s do this by creating a tiny Delphi DLL/*.so library. This library exports a single function that takes a double and returns its double value.
build-dll-using-delphi-for-linux-64-bit
And, as you hit F9 to build, you will have the libProject6.so file, the Linux *.so library (if you change target platform to Windows, the code will be compiled into Project6.dll automatically, that is the beauty of the Delphi IDE).
HOW TO USE THE DYNAMIC LINK LIBRARY IN C++ LINUX (GCC COMPILER)?
Copy the file to Ubuntu and create the following C/C++ source code in the same directory.
1 |
// https://helloacm.com/how-to-use-the-dynamic-link-library-in-c-linux-gcc-compiler/ |
The RTLD_LAZY resolves undefined symbols when code from the dynamic library is executed, which is faster to open. Alternatively, RTLD_NOW resolves all undefined symbols before dlopen returns and fails if this cannot be done.
Compile the source code using (-ldl, the Interfaces for Dynamic Loader):
1 |
gcc -o test test.cpp -ldl |
Run the test which should print a nice:
1 |
root@helloacm.com:/home/delphi# ./test |
–EOF (The Ultimate Computing & Technology Blog) —
https://helloacm.com/how-to-use-the-dynamic-link-library-in-c-linux-gcc-compiler/
https://helloacm.com/delphi-compiles-code-to-linux-64-bit-server/
https://helloacm.com/quick-review-delphi-10-2-tokyo-preview/
How to Use the Dynamic Link Library in C++ Linux (C++调用Delphi写的.so文件)的更多相关文章
- Walkthrough: Creating and Using a Dynamic Link Library (C++)
Original Link: http://msdn.microsoft.com/zh-cn/library/ms235636.aspx Following content is only used ...
- Custom Action : dynamic link library
工具:VS2010, Installshield 2008 实现功能: 创建一个C++ win32 DLL的工程,MSI 工程需要调用这个DLL,并将Basic MSI工程中的两个参数,传递给DLL, ...
- DYNAMIC LINK LIBRARY - DLL
https://www.tenouk.com/ModuleBB.html MODULE BB DYNAMIC LINK LIBRARY - DLL Part 1: STORY What do we h ...
- Walkthrough: Create and use your own Dynamic Link Library (C++)
参考网站:https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-librar ...
- 动态链接库(Dynamic Link Library)学习笔记(附PE文件分析)
转载:http://www.cnblogs.com/yxin1322/archive/2008/03/08/donamiclinklibrary.html 作者:EricYou 转载请注明出处 注 ...
- [DLL] Dynamic link library (dll) 的编写和使用教程
前一阵子,项目里需要导出一个DLL,但是导出之后输出一直不怎么对,改了半天才算改对...读了一些DLL教程,感觉之后要把现在的代码导出,应该还要花不少功夫...下面教程参照我读的3个教程写成,所以内容 ...
- 动态链接库(Dynamic Link Library)
DLL INTRODUCTION A DLL is a library that contains code and data that can be used by more than one pr ...
- How to Create DLL(Dynamic link library)
该文章属于在YouTube视频上看到的,链接如下: https://www.youtube.com/watch?v=EmDJsl7C9-k&t=3s 1.创建一个工程并建立一个控制台程序 2. ...
- Linux Dynamic Shared Library && LD Linker
目录 . 动态链接的意义 . 地址无关代码: PIC . 延迟版定(PLT Procedure Linkage Table) . 动态链接相关结构 . 动态链接的步骤和实现 . Linux动态链接器实 ...
随机推荐
- 解决gdb 调试 core 文件函数名显示为问号的问题
关于gdb调试core文件总是一堆问号的问题 问题描写叙述:已经在编译选项中增加了-g,可是查看core文件时.还是一堆问号,使用的命令为:gdb -c core 解决方式:因为gdb -c core ...
- 有奖试读&征文--当青春遇上互联网,是否能点燃你的创业梦
时至今日,互联网已经切入我们每一个人的工作.生活和学习的每一个角落.利用互联网这个工具,有人游戏,有人购物,有人上课,有人交友,而有那么一部分人去利用它完毕人生最完美的逆袭.相信每一个人心中都有个创业 ...
- 80. Domino Internet Password
Internet口令保存在Domino文件夹的个人文档的HTTPPassword域中,和文档中的username一起用于藉各种Internet协议訪问Dominoserver时的校验,最经常使用的就是 ...
- 【严肃脸】使用caffe实现色情图片的识别
前言 前几天看到了雅虎开源了一个色情图片的识别模型新闻,上Github一看,是基于caffe的.试了试,模型效果很赞.Github地址:https://github.com/yahoo/open_ns ...
- 【第400篇题解纪念2016年10月28日】【28.10%】【codeforces 617E】XOR and Favorite Number
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- ubuntu 16.0.4 中docker 部署 sqlserver 2017(四)
1. 从 Docker Hub 中拉出 SQL Server 2017 Linux 容器映像 sudo docker pull mcr.microsoft.com/mssql/server:2017- ...
- C#3 分部方法,简单标记一下
如果我问你,如果一个普通的类实现了一个接口方法,但是这个类的实例却访问不到这个接口的方法,这种情况你遇到过吗?有时候,你可能在使用分部方法时就会发现这么一个现象. C#3 中出现了 “分部方法” ,工 ...
- Android中的后台邮件发送
一.调用邮件发送工具类进行邮件发送 new Thread(){ public void run() { try { GMailSender sender = new GMailSender( &quo ...
- CSS动作
5.过渡 tansition (由一个状态过渡到另外一个状态的过程) transition 过渡 参数1: ...
- 2.RabbitMQ的quick start
1.首先要安装 RabbitMQ Client 2.创建一个控制台项目 取名 Publisher代码如下: using RabbitMQ.Client; using System; using Sys ...