我正在尝试从 cassandra-cpp 板条箱运行 simple 示例,但由于链接器错误而无法编译(请参阅下面的错误)。第一次遇到带有 C 依赖项的 lib,我不知道如何使其在本地编译/运行。
错误
error: linking with `cc` failed: exit status: 1
|
= note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL=
= note: ld: warning: search path '/usr/lib/x86_64-linux-gnu' not found
ld: warning: search path '/usr/local/lib/x86_64-linux-gnu' not found
ld: warning: search path '/usr/local/lib64' not found
ld: warning: search path '/usr/lib64/' not found
ld: warning: search path '/usr/local/opt/openssl/lib' not found
ld: library 'cassandra' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
代码 - main.rs
use cassandra_cpp::*;
#[tokio::main]
async fn main() -> Result<()> {
let mut cluster = Cluster::default();
cluster.set_contact_points("127.0.0.1").unwrap();
cluster.set_load_balance_round_robin();
let session = cluster.connect().await?;
let result = session
.execute("SELECT keyspace_name FROM system_schema.keyspaces;")
.await?;
println!("{}", result);
let mut iter = result.iter();
while let Some(row) = iter.next() {
let col: String = row.get_by_name("keyspace_name")?;
println!("ks name = {}", col);
}
Ok(())
}
Cargo.toml
[package]
name = "rust_cassandra"
version = "0.1.0"
edition = "2021"
[dependencies]
cassandra-cpp = "3.0.2"
tokio = { version = "1.39.2", features = ["rt", "rt-multi-thread", "macros"] }
请帮助我如何使用cargo run在本地编译和运行
编辑
我也安装了我提到的 pre-req datastax 驱动程序,但仍然没有运气,我也尝试通过创建 dockerfile 来安装 floki。
问题已通过 openssl 的符号链接修复。按照库中所述安装 cpp 驱动程序后,确保安装 openssl 并在终端中导出以下路径或在 bash/zsh 配置中添加为 env 路径
export LIBRARY_PATH=$(brew --prefix openssl@3)/lib:/usr/local/lib:/usr/lib:$LIBRARY_PATH
export LIBRARY_PATH=/opt/homebrew/opt/libuv/lib:$LIBRARY_PATH