On Sunday, 27 November 2016 at 12:59:32 UTC, Timoses wrote:
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...

The missing symbol is the struct initialiser for neo4j_map_entry_t. Not sure why is not being generated (it should), possibly because of the union.

That seems like a bug please report it. http://issues.dlang.org/

Reply via email to