D语言导入本地模块
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 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
您不会在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 fora.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.这个问题还不清楚,但听起来您想通过配音创建一个库,然后在另一个项目中使用该库。那是对的吗?
例如,您的项目可能具有类似的结构:
如果这是您要执行的操作,则应考虑使用DUB 子包装。
例如,
myProject/dub.sdl
可能看起来像:您的公共库在
myproject/common/common/dub.sdl.sdl
可能看起来像这样:像
myproject/program1/dub.sdl
中的这样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:
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:Your common library at
myProject/common/dub.sdl
may look like this:And finally you would depend on it like this in
myProject/program1/dub.sdl
: