C++ Cassandra 构建错误

标签 c++ cassandra clion libs

您好,我在用 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/

相关文章:

c++ - 如何使用赋值运算符声明函数?

debugging - 如何在 CLion 中添加十六进制 watch ?

c++ - 无法运行任何c/c++程序

c++ - 如果只知道基类,如何传递派生类?

c++ - 显式运算符的隐式转换

c++ - 什么时候应该使用 decltype(x) 而不是 auto 来声明变量的类型?

cassandra - Cassandra 新手,无法理解复制拓扑

cassandra - 在 cassandra 中使用 replication_factor

r - 在 Cassandra 中将宽表转换为长格式

c++ - WSL 看不到环境变量