Creating array of structs being used in C interface

Timoses via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Nov 27 04:59:32 PST 2016


Hi there,

I've got a problem interfacing to a C library.
The following structs are used by the library's .d file that I've 
written.

--------------------
struct neo4j_map_entry_t
{
     neo4j_value_t key;
     neo4j_value_t value;
};

struct neo4j_value_t
{
     uint8_t _vt_off;
     uint8_t _type; /*TODO: combine with _vt_off? (both always 
have same value)*/
     uint16_t _pad1;
     uint32_t _pad2;
     _neo4j_value_data _vdata;
};

union _neo4j_value_data
{
     uint64_t _int;
     uintptr_t _ptr;
     double _dbl;
};
--------------------

Now I'd also like to use them in my own code. However, I fail at 
generating an array of map entries:

--------------------
void test()
{
     // These work
     neo4j_map_entry_t[] mapa2; // yes
     neo4j_map_entry_t entry1 = { key: neo4j_string("prop1"), 
value: neo4j_string("testprop1")}; // yes
     neo4j_map_entry_t entry2 = { key: neo4j_string("prop2"), 
value: neo4j_string("testprop2")}; // yes
     neo4j_map_entry_t* mapp; // yes

     // These don't
     neo4j_map_entry_t[2] mapa1; // no
     mapa2.length = 2; // no
     mapa2 ~= entry1; // no
     neo4j_map_entry_t[] mapa3 = [{ key: neo4j_null, value: 
neo4j_null}]; // no
}
--------------------

The output is:
______________________
myprogram ~master: building configuration "unittest"...
Linking...
Undefined symbols for architecture x86_64:
   "_D10neo4jTypes17neo4j_map_entry_t6__initZ", referenced from:
       _D6myprogram6myprogram5test2MFZv in myprogram.o
ld: symbol(s) not found for architecture x86_64
______________________

Why is it a linker problem? I'm not linking to the c interface 
but merely using D structs...



More information about the Digitalmars-d-learn mailing list