3

Hello.

First I'm sorry for my ita-english.

I want use gwan with aerospike but when run the servlet...problem. I start with this example.c of aerospike. In file example.c I put gwan.h and this is the output ./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.

Inside 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;
}

how can connect aerospike with gwan? Thank you

Community
  • 1
  • 1
user112752
  • 131
  • 1
  • 1
  • 9

3 Answers3

1

You need to #pragma link your aerospike library, and make sure all your required header files are in the right place. See G-WAN FAQ or read example code in the G-WAN tarball.

Also, in G-WAN the return code of the main function will be used as HTTP response code, so avoid return -1;.

Nagi
  • 256
  • 1
  • 2
  • 4
  • i do this: #pragma link "/usr/lib/libaerospike.so" #include "aerospike/aerospike.h" #include "aerospike/aerospike_key.h" but now say: "Linking prova.c /usr/lib/libaerospike.so undefined symbol: RAND_seed" – user112752 Mar 03 '15 at 19:17
  • At this point, G-WAN is not the wall you're facing anymore. It looks like you're still missing some of the aerospike headers. I tried to install aerospike on my system, but it seems they only provide 64bit packages... – Nagi Mar 05 '15 at 13:33
  • I made sure that everything is 64bit, my system (debian7.8 64bit), aerospike, gwan and the client c of aerospike. At this point I do not know what to do – user112752 Mar 05 '15 at 18:06
  • Have you tried to compile the original example code? Is there any special instruction on compiling it? You can start from there. – Nagi Mar 06 '15 at 02:06
  • Some guy teel me: following flags for ld line: LDFLAGS = -lssl -lcrypto -lpthread ifneq ($(OS),Darwin) LDFLAGS += -lrt -ldl endif, in makefile? if this gwan compile onfly without make file...right? – user112752 Mar 09 '15 at 15:15
  • Flags `-lssl -lcrypto -lpthread -lrt -ldl` tells the compiler to link libraries - in G-WAN you link libraries with... `#pragma link` :-) The libraries are probably `libssl`, `libcrypto`, `librt` and `libdl`. – Nagi Mar 09 '15 at 15:47
0

undefined symbol: g_namespace

the error message is clear. As long as this variable is undefined your C servlet won't compile.

I don't know your library but this variable is probably defined in a library include file - or must be defined by the end user (you). Check the library documentation.

Gil
  • 3,279
  • 1
  • 15
  • 25
0

Detailed steps to run Aerospike C-client example with G-WAN,

  1. Download and extract G-WAN server tar on your system
  2. You can start the G-WAN server using ./gwan script present in extracted folder, e.g. ./gwan_linux64-bit/
  3. Get Aerospike C-client from https://github.com/aerospike/aerospike-client-c, and install on your system
  4. Copy example.c to ./gwan_linux64-bit/0.0.0.0_8080/#0.0.0.0/csp/
  5. Make following changes to example.c,

    • Add following #pragma directive,
      #pragma include "/home/user/aerospike-client-c/examples/utils/src/include/"
      This will help search example_utils.h, which is necessary for all the example scripts in C-client.
    • Add following #pragma directive,
      #pragma link "/home/user/aerospike-client-c/examples/utils/src/main/example_utils.c"
      We shall have to link example_utils.c, as it has definitions of all util functions used in example scripts.
  6. Make changes to the return values. Retun proper HTTP error codes.

  7. Now, you are good to go. Run ./gwan server and access your webservice through browser, http://127.0.0.1:8080/?example.c

Aashish P
  • 1,894
  • 5
  • 22
  • 36