D语言导入本地模块

发布于 2025-01-19 23:48:32 字数 310 浏览 4 评论 0原文

我是D语言新手。我有一个项目A。当我执行dub build时,它创建了libA.so。我正在尝试创建一个不同的 .d 文件并导入此模块。

现在我想编写一个 D 包装器来使用它。

当我尝试

导入

时它不起作用。我将 libA.so 复制到 sudo cp libA.so /usr/include/dmd/druntime/import/ 但导入不起作用。

你能帮我如何导入这个吗?

I am new to D language. i have a project A. When i executed dub build it has created me libA.so. i am trying to create a different .d file and import this module.

now i wanted to write a D wrapper to consume it.

when i tried

import a

it did not work. i copied the libA.so to the sudo cp libA.so /usr/include/dmd/druntime/import/ but the import did not work.

Can you please help me how can i import this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2025-01-26 23:48:32

在 Linux 上用 D 编写和使用共享库的官方文档位于:

https://dlang。 org/articles/dll-linux.html

The official documentation for writing and using shared libraries in D on Linux is here:

https://dlang.org/articles/dll-linux.html

苹果你个爱泡泡 2025-01-26 23:48:32

您不会在D中导入共享库。导入模块(源文件)。因此,.so文件不属于导入目录。您需要链接导入表示编译器将搜索AD的导入路径。这就是您的进口目录中需要的。如果您的库有多个源文件,则它们每个都需要在导入路径上并单独导入。

You don't import shared libraries in D. You import modules (source files). So the .so file does not belong in the import directory. You need to link to that. import a means the compiler will search the import path for a.d. That's what needs to be in your import directory. If your library has multiple source files, they each need to be on the import path and imported separately.

梦亿 2025-01-26 23:48:32

这个问题还不清楚,但听起来您想通过配音创建一个库,然后在另一个项目中使用该库。那是对的吗?

例如,您的项目可能具有类似的结构:

myProject
├- commonLib
|
├- program1
|  (depends on commonLib)
└- program2
   (depends on commonLib)

如果这是您要执行的操作,则应考虑使用DUB 子包装

例如,myProject/dub.sdl可能看起来像:

name "myProject"
targetType "none"
dependency "myProject:common" path="."
dependency "myProject:program1" path="."
dependency "myProject:program2" path="."
subPackage "./common/"
subPackage "./program1/"
subPackage "./program2/"

您的公共库在myproject/common/common/dub.sdl.sdl可能看起来像这样

name "common"
targetType "library"

:像myproject/program1/dub.sdl中的这样

name "program1"
targetType "executable"
dependency "myProject:common" path="../"

The question is a bit unclear, but it sounds like you want to create a library via dub, and then use that library in another project. Is that correct?

For example, your project may have a structure like:

myProject
├- commonLib
|
├- program1
|  (depends on commonLib)
└- program2
   (depends on commonLib)

If this is what you are trying to do, you should consider using Dub sub-packages.

For example, myProject/dub.sdl might look like this:

name "myProject"
targetType "none"
dependency "myProject:common" path="."
dependency "myProject:program1" path="."
dependency "myProject:program2" path="."
subPackage "./common/"
subPackage "./program1/"
subPackage "./program2/"

Your common library at myProject/common/dub.sdl may look like this:

name "common"
targetType "library"

And finally you would depend on it like this in myProject/program1/dub.sdl:

name "program1"
targetType "executable"
dependency "myProject:common" path="../"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文