C ++ Cassandra构建错误

时间:2018-04-10 19:11:02

标签: c++ cassandra clion libs

您好我在使用c ++构建代码时遇到问题。 我已经在我的Mac OS上安装了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;
}

1 个答案:

答案 0 :(得分:1)

在MacOS上,默认安装目录为/usr/local,其中头文件安装在include中,库安装在lib中。为确保正确安装驱动程序,您可以通过clang++

编译示例代码
clang++ <source_file_name> -o <executable_output> -lcassandra

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