【问题标题】:connection gwan with aerospike db in C在 C 中连接 gwan 与 aerospike db
【发布时间】:2015-05-02 05:38:21
【问题描述】:

你好。

首先我很抱歉我的 ita-english。

我想将 gwan 与 aerospike 一起使用,但是在运行 servlet 时...问题。 我从 aerospike 的这个 example.c 开始。在文件 example.c 中,我放了 gwan.h,这是输出 ./gwan:

loading
        hello.cs: to use   .cs scripts, install C#..
       hello.lua: to use  .lua scripts, install Lua
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Linking example.c: undefined symbol: g_namespace
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To run G-WAN, you must fix the error(s) or remove this Servlet.

在example.c里面:

#include "gwan.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

#include <aerospike/aerospike.h>
#include <aerospike/aerospike_key.h>
#include <aerospike/aerospike_query.h>
#include <aerospike/as_error.h>
#include <aerospike/as_key.h>
#include <aerospike/as_query.h>
#include <aerospike/as_record.h>
#include <aerospike/as_status.h>
#include <aerospike/as_val.h>
#include "example_utils.h"
const char TEST_INDEX_NAME[] = "test-bin-index";
bool query_cb(const as_val* p_val, void* udata);
void cleanup(aerospike* p_as);
bool insert_records(aerospike* p_as);
int
main(int argc, char* argv[])
{
if (! example_get_opts(argc, argv, EXAMPLE_MULTI_KEY_OPTS)) {
    exit(-1);
}
aerospike as;
example_connect_to_aerospike(&as);
example_remove_test_records(&as);
example_remove_index(&as, TEST_INDEX_NAME);
if (! example_create_integer_index(&as, "test-bin", TEST_INDEX_NAME))
{   
    cleanup(&as);
    exit(-1);
}
if (! insert_records(&as)) {
    cleanup(&as);
    exit(-1);
}
if (! example_read_test_records(&as)) {
    cleanup(&as);
    exit(-1);
}
as_error err;
as_query query;
as_query_init(&query, g_namespace, g_set);
as_query_where_inita(&query, 1);
as_query_where(&query, "test-bin", as_integer_equals(7));
LOG("executing query: where test-bin = 7");
if (aerospike_query_foreach(&as, &err, NULL, &query, query_cb, NULL)
        != AEROSPIKE_OK) {
    LOG("aerospike_query_foreach() returned %d - %s", err.code,
            err.message);
    as_query_destroy(&query);
    cleanup(&as);
    exit(-1);
}
LOG("query executed");
as_query_destroy(&query);
cleanup(&as);
LOG("simple query example successfully completed");
return 0;
}
bool
query_cb(const as_val* p_val, void* udata)
{
if (! p_val) {
    LOG("query callback returned null - query is complete");
    return true;
}
as_record* p_rec = as_record_fromval(p_val);
if (! p_rec) {
    LOG("query callback returned non-as_record object");
    return true;
}
LOG("query callback returned record:");
example_dump_record(p_rec);
return true;
}
void
cleanup(aerospike* p_as)
{
example_remove_test_records(p_as);
example_remove_index(p_as, TEST_INDEX_NAME);
example_cleanup(p_as);
}
bool
insert_records(aerospike* p_as)
{
set
as_record rec;
as_record_inita(&rec, 1);
for (uint32_t i = 0; i < g_n_keys; i++) {
    as_error err;
    as_key key;
    as_key_init_int64(&key, g_namespace, g_set, (int64_t)i);
    as_record_set_int64(&rec, "test-bin", (int64_t)i);
    if (aerospike_key_put(p_as, &err, NULL, &key, &rec) !=     AEROSPIKE_OK) {
        LOG("aerospike_key_put() returned %d - %s", err.code, err.message);
        return false;
    }
}

LOG("insert succeeded");

return true;
}

如何将 aerospike 与 gwan 连接起来? 谢谢

【问题讨论】:

    标签: c aerospike g-wan database nosql


    【解决方案1】:

    您需要#pragma link 您的 aerospike 库,并确保所有所需的头文件都在正确的位置。请参阅G-WAN FAQ 或阅读 G-WAN 压缩包中的示例代码。

    另外,在 G-WAN 中,主函数的返回码将用作 HTTP 响应码,因此请避免使用return -1;

    【讨论】:

    • 我这样做:#pragma link "/usr/lib/libaerospike.so" #include "aerospike/aerospike.h" #include "aerospike/aerospike_key.h" 但现在说:"Linking prova .c /usr/lib/libaerospike.so 未定义符号:RAND_seed"
    • 此时,G-WAN 不再是您面临的墙。看起来您仍然缺少一些 aerospike 接头。我试图在我的系统上安装 aerospike,但它们似乎只提供 64 位软件包...
    • 我确保一切都是 64 位的,我的系统(debian7.8 64 位)、aerospike、gwan 和 aerospike 的客户端 c。此时我不知道该怎么办
    • 你试过编译原始示例代码吗?编译时有什么特别的说明吗?你可以从那里开始。
    • 有人告诉我: ld 行的以下标志: LDFLAGS = -lssl -lcrypto -lpthread ifneq ($(OS),Darwin) LDFLAGS += -lrt -ldl endif,在 makefile 中?如果这个 gwan 在没有 make 文件的情况下只编译......对吗?
    【解决方案2】:

    未定义符号:g_namespace

    错误信息很清楚。只要未定义此变量,您的 C servlet 就不会编译。

    我不知道您的库,但此变量可能是在库包含文件中定义的 - 或者必须由最终用户(您)定义。检查库文档。

    【讨论】:

      【解决方案3】:

      使用 G-WAN 运行 Aerospike C 客户端示例的详细步骤,

      1. 在您的系统上下载并解压 G-WAN 服务器 tar
      2. 您可以使用解压缩文件夹中的./gwan 脚本启动 G-WAN 服务器,例如./gwan_linux64-bit/
      3. https://github.com/aerospike/aerospike-client-c 获取 Aerospike C 客户端,并安装到您的系统上
      4. 将example.c复制到./gwan_linux64-bit/0.0.0.0_8080/#0.0.0.0/csp/
      5. 对 example.c 进行以下更改,

        • 添加以下 #pragma 指令,
          #pragma include "/home/user/aerospike-client-c/examples/utils/src/include/"
          这将有助于搜索 example_utils.h,这对于 C 客户端中的所有示例脚本都是必需的。
        • 添加以下 #pragma 指令,
          #pragma link "/home/user/aerospike-client-c/examples/utils/src/main/example_utils.c"
          我们必须链接 example_utils.c,因为它定义了示例脚本中使用的所有 util 函数。
      6. 更改返回值。重新调整正确的 HTTP 错误代码。

      7. 现在,您可以开始了。运行./gwan服务器并通过浏览器访问您的网络服务,http://127.0.0.1:8080/?example.c

      【讨论】:

      • 欢迎。如果您在这方面遇到任何问题,请随时打扰我。
      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2022-10-21
      • 2016-05-03
      • 1970-01-01
      • 2011-07-05
      • 2016-03-04
      • 1970-01-01
      相关资源
      最近更新 更多