英文:
Rust packaged in .deb
问题
我想将我的Rust代码创建成一个.deb
软件包。它包括一个库(crate),被另一个库crate和一个二进制crate使用。所以类似于
- core_lib
- pam_lib(使用core_lib)
- cli_binary(使用core_lib)
问题1
问题是解决依赖关系,当然了 我尝试过两种方法:
动态链接
在编译代码时,我可以强制它期望在哪里找到共享库,例如cargo rustc -r -- -C link-args='-Wl,-rpath,/usr/lib/x86_64-linux-gnu/mylib'
。然而,当我这样做并且dpkg build
软件包时,lintian
返回一个错误:custom-library-search-path
。
添加到ldconfig
我还可以在/etc/ld.so.conf.d/
目录中添加一个新的配置文件,并设置路径到/usr/lib/x86_64-linux-gnu/mylib
目录,然后在postinst
脚本中执行sudo ldconfig
以更新值。但**这是否是正确的方法?**我不想遵循任何反模式。
问题2
我遇到的另一个问题是,当我编译任何一个“最终”二进制文件时,它也会在target/release
文件夹中编译core_lib
。到目前为止,一切都很好。但是libcore_lib.so
在我编译pam_lib
或cli_binary
时不同(甚至字节大小也有点不同),我不能互换使用它们。即使我独立编译core_lib
并使用该构件,运行任何一个二进制文件都会返回unknown symbol
,后面跟着一个来自core_lib
的函数引用。
一个可能的解决方案是将libcore_lib.so
复制两次到不同的目录(分别为每个二进制文件从它们自己的target/release
目录),但由于它应该是一个共享引用,这似乎是明显的... 愚蠢。
有什么想法,请?
核心库的Cargo.toml
:
[package]
name = "core-lib"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["dylib"]
[dependencies]
...
和二进制文件的Cargo.toml
:
[package]
name = "cli-binary"
version = "0.1.0"
edition = "2021"
[dependencies]
core-lib = { path = "../../Rust core/core-lib" }
...
(Note: The code portions are not translated as per your request.)
英文:
I want to create a .deb
package out of my Rust code. It consists of a library (crate) that is used by another library crate and a binary crate. So something like
- core_lib
- pam_lib (uses core_lib)
- cli_binary (uses core_lib)
Question 1
The issue is resolving dependencies, of course I have tried two approaches:
Dynamic linking
When compiling the code, I can force where it should expect shared libraries to be found, as cargo rustc -r -- -C link-args='-Wl,-rpath,/usr/lib/x86_64-linux-gnu/mylib'
. However, when I do this and dpkg build
the package, lintian
returns an error: custom-library-search-path
.
Adding to ldconfig
I can also add a new config file to /etc/ld.so.conf.d/
and set a path to my /usr/lib/x86_64-linux-gnu/mylib
dir, and execute sudo ldconfig
in a postinst
script to update the values. But is this the right way to go? I wouldn't like to follow any antipatterns.
Question 2
The other issue I'm having with these dependencies is that when I compile either of the 'final' binaries, it also compiles the core_lib
in the target/release
folder. So far, so good. But libcore_lib.so
is not the same when I compile pam_lib
or cli_binary
(even byte size is somewhat different), and I cannot use them interchangeably. Not even when I compile core_lib
independently and use that artifact; running either binary returns unknown symbol
followed by a reference to a function from core_lib
.
One possible solution would be to copy libcore_lib.so
twice to different dirs (once for each binary from their own target/release
dir), but since it is supposed to be a shared reference, that seems to be outright... stupid.
Any ideas, please?
Core library Cargo.toml
:
[package]
name = "core-lib"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["dylib"]
[dependencies]
...
and binaries Cargo.toml
:
[package]
name = "cli-binary"
version = "0.1.0"
edition = "2021"
[dependencies]
core-lib = { path = "../../Rust core/core-lib" }
...
答案1
得分: 0
好的,以下是翻译好的内容:
"Okay, the dumb part was... me
I was also browsing Rust forum and stumbled upon a topic that resembled mine - and sure enough, when I changed the core_lib
type from dylib
to lib
, it all started working. I just imposed a lot of headache upon me by using dylib
for no real reason (switched to that long time ago for reasons I no longer remember... sigh).
Anyway, hope it helps someone else, too.
英文:
Okay, the dumb part was... me
I was also browsing Rust forum and stumbled upon a topic that resembled mine - and sure enough, when I changed the core_lib
type from dylib
to lib
, it all started working. I just imposed a lot of headache upon me by using dylib
for no real reason (switched to that long time ago for reasons I no longer remember... sigh).
Anyway, hope it helps someone else, too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论