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动态链接器实 ...
随机推荐
- 【BZOJ 1025】[SCOI2009]游戏
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 [题意] [题解] 每一个对应关系,里面其实都会生成大小不一的几个环. 每一个环 ...
- linux 网卡配置文件详解
配置文件位置:/etc/sysconfig/network-scripts/ifcfg-eth0 1. DEVICE=eth0 网卡的名字 2. HWADDR=00:0c:29:90:89:d9 HW ...
- Swift 中的Closures(闭包)详解
Swift 中的Closures(闭包)详解 在Swift没有发布之前,所有人使用OC语言编写Cocoa上的程序,而其中经常被人们讨论的其中之一 -- Block 一直备受大家的喜爱.在Swift中, ...
- JSP和Servlet学习笔记1 - 访问配置
1. 访问 WebContent 目录下的 JSP 文件 在 WebContent 目录下的文件可以直接在浏览器中访问.新建一个 test.jsp 文件 <%@ page language=&q ...
- Light libraries是一组通用的C基础库,目标是为减少重复造轮子而写(全部用POSIX C实现)
Light libraries是一组通用的C基础库,目标是为减少重复造轮子而写实现了日志.原子操作.哈希字典.红黑树.动态库加载.线程.锁操作.配置文件.os适配层.事件驱动.工作队列.RPC.IPC ...
- 【JDBC】java PreparedStatement操作oracle数据库
************************************************************************ ****原文:blog.csdn.net/clark_ ...
- PCI GXL学习之再造篇
作者:朱金灿 来源:http://blog.csdn.net/clever101 再造一个PCI GXL?听起来是一件颇有难度的事,实际上并非不可能.本文拟从必要性.可行性和技术路线等方面谈谈再造PC ...
- WPF--常用布局介绍
概述:本文简要介绍了WPF中布局常用控件及布局相关的属性 1 Canvas Canvas是一个类似于坐标系的面板,所有的元素通过设置坐标来决定其在坐标系中的位置..具体表现为使用Left.Top.Ri ...
- 它们的定义Activity跳转动画
本来觉得是一个非常小的需求, 后来我发现总是 错误, 采用Theme于 4.0在 操作不是很容易使用. 后来查阅资料, 须要在finish 后面 和 startActivity 后面加入 overri ...
- PHP正则表达式入门教程[转]
思维导图 点击下图,可以看具体内容! 介绍 正则表达式,大家在开发中应该是经常用到,现在很多开发语言都有正则表达式的应用,比如javascript,java,.net,p ...