gpt4 book ai didi

C++ Cassandra 构建错误

转载 作者:行者123 更新时间:2023-11-30 05:02:39 32 4
gpt4 key购买 nike

你好,我在用 C++ 构建代码时遇到了问题。我已经在我的 Mac 操作系统上安装了 cassandra 以及我需要从 datastax 获得的所有库。但是当我构建我的测试项目时,我总是得到

     Undefined symbols for architecture x86_64:
"_cass_cluster_free", referenced from:
_main in main.cpp.o
"_cass_cluster_new", referenced from:
_main in main.cpp.o
"_cass_cluster_set_contact_points", referenced from:
_main in main.cpp.o
"_cass_error_desc", referenced from:
_main in main.cpp.o
"_cass_future_error_code", referenced from:
_main in main.cpp.o
"_cass_future_free", referenced from:
_main in main.cpp.o
"_cass_session_connect", referenced from:
_main in main.cpp.o
"_cass_session_free", referenced from:
_main in main.cpp.o
"_cass_session_new", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64

我知道我的 CMakelist 中遗漏了一些东西,但我不知道到底是什么

这是我的测试代码:

#include <cassandra.h>
#include <cstdio>

int main() {
/* Setup and connect to cluster */
CassCluster* cluster = cass_cluster_new();
CassSession* session = cass_session_new();

/* Add contact points */
cass_cluster_set_contact_points(cluster, "127.0.0.1");

/* Provide the cluster object as configuration to connect the session */
CassFuture* connect_future = cass_session_connect(session, cluster);

/* This operation will block until the result is ready */
CassError rc = cass_future_error_code(connect_future);

printf("Connect result: %s\n", cass_error_desc(rc));

/* Run queries... */

cass_future_free(connect_future);
cass_session_free(session);
cass_cluster_free(cluster);

return 0;
}

最佳答案

在 MacOS 上,默认安装目录是 /usr/local头文件安装在 include 中和正在安装的库 lib .为确保正确安装驱动程序,您可以通过 clang++ 编译您的示例代码

clang++ <source_file_name> -o <executable_output> -lcassandra

要解决您的 CMake ( CMakelists.txt) 配置问题,您需要确保使用 target_link_libraries(<target> cassandra) 以便您的应用程序链接到系统上安装的驱动程序库。

关于C++ Cassandra 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49761274/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com