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动态链接器实 ...
随机推荐
- P2P理财友情提示
最近2年,P2P理财非常火,但是出现的问题也是越来越频繁. 2014年12月,据说有70多家平台出现了问题,加上以前的,一共有300多家了,出现问题的占总比有20%~30%了. 这个真的是非常的可怕. ...
- CSS拾遗(二)
接CSS拾遗(一). 4. 不透明度 opacity: 0.8; filter: alpha(opacity=80); opacity: 0.8是标准的写法:filter: alpha(opacity ...
- 在 Oracle 中新建 SDE 用户
--1.创建用户(SDE)和密码(SDE) CREATE USER SDE IDENTIFIED BY SDE --2.创建表空间(SDE) CREATE TABLESPACE SDE DATAFIL ...
- Android 它们的定义View
安卓开发过程,安卓官方控制有时来自往往不能满足我们的需求.这一次,我必须定义自己.下面我们就来看看他们的定义View: package com.example.myview; import andro ...
- WPF,Silverlight与XAML读书笔记第三十九 - 可视化效果之3D图形
原文:WPF,Silverlight与XAML读书笔记第三十九 - 可视化效果之3D图形 说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘> ...
- AutoEncoder一些实验结果,并考虑
看之前Autoencoder什么时候,我做了一些练习这里:http://ufldl.stanford.edu/wiki/index.php/Exercise:Sparse_Autoencoder .其 ...
- EBS OAF 发展 URL商标、加密和编码
EBS OAF 发展 URL商标.加密和编码 (版权声明.我原来的或翻译的文章,如需转载,转载的个人学习,转载请注明出处:否则,请与我联系.版权所有) 马克 当您指定页面定义声明URL参数,文本也能够 ...
- 算法(algorithm)、模型(model)与框架(framework)
模型对应的数学公式,公式中往往有待学习得到的参数,因此在进行训练或者学习时,首先初始化这部分参数(0 或标准正太分布): 学习之前的初始化:initial model: 学习完成之后的模型:final ...
- linux_ linux下查看最消耗CPU、内存的进程 20
1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10个进程 ps auxw|head -1;ps a ...
- hibernate关于多对多注解配置
Game实体类配置关系 @Entity @Table(name = "game") public class Game { @Id @GeneratedValue private ...