RejectedSoftware Forums

Sign up

json serialization

When using json like below, I get undefined references. Perhaps import statements inside a function do not export for the linker? When I move the two lines to the top of the file it works. This is on linux.

writeln("As json ", serializeToJson(c));

Thanks,
Dan

151	import std.utf;
152	import vibe.utils.string;

$ rdmd -g -w -property -I/.../vibe.d/source -L-leventpthreads -L-levent -L-lssl -L-lcrypto .../client.d
/tmp/.rdmd-1000/rdmd-client.d-C6514453AD5E608E1F0464559AC6864F/objs/client.o: In function `
D4vibe6stream6stream11readAllUtf8FC4vibe6stream6stream11InputStreambmZAya':
/.../vibe.d/source/vibe/stream/stream.d:154: undefined reference to _D4vibe5utils6string12sanitizeUTF8FxAhZAya'<br>/.../vibe.d/source/vibe/stream/stream.d:154: undefined reference to D4vibe5utils6string12stripUTF8BomFAyaZAya'
/.../vibe.d/source/vibe/stream/stream.d:157: undefined reference to `
D4vibe5utils6string12stripUTF8BomFAyaZAya'
collect2: ld returned 1 exit status
--- errorlevel 1

Re: json serialization

Am 10/17/2012 8:37 PM, schrieb undefined reference linux:

When using json like below, I get undefined references. Perhaps import
statements inside a function do not export for the linker? When I move
the two lines to the top of the file it works. This is on linux.

(...)

rdmd, which is used by the vibe script, parses the output of dmd -deps
to calculate the neede files. Unfortunately, dmd's output only includes
global imports and neither local imports, nor string imports.

There is DMD bug report for this, but it didn't get attention yet:
http://d.puremagic.com/issues/show_bug.cgi?id=7016

Re: json serialization

On Wed, 17 Oct 2012 21:15:19 +0200, Sönke Ludwig wrote:

rdmd, which is used by the vibe script, parses the output of dmd -deps
to calculate the neede files. Unfortunately, dmd's output only includes
global imports and neither local imports, nor string imports.

There is DMD bug report for this, but it didn't get attention yet:
http://d.puremagic.com/issues/show_bug.cgi?id=7016

Ok, thanks. I've not seen function scoped imports, so curious as to the
purpose/benefit? Is it to reduce the effect of the symbols being imported
to just the function to prevent name collisions?

Anyway, I like the json serialize functionality and I'm just getting into
vibe. Moving the imports to the top made it work for my very simple use case
and I hope it doesn't break other stuff in vibe for me later.

Thanks
Dan

Re: json serialization

Am 10/18/2012 12:48 PM, schrieb Dan:

Ok, thanks. I've not seen function scoped imports, so curious as to the
purpose/benefit? Is it to reduce the effect of the symbols being imported
to just the function to prevent name collisions?

I'd say that is one possible reason. They can also be useful to keep
code and dependencies closer together when an import is really just
needed for one function. But another very nice side effect in the vibe.d
context is that they allow imports to be specified inside of Diet
templates - that feature would probably be impossible without them.