user2943202
user2943202

Reputation:

How can I resolve this error when linking to zlib under Linux in a D application?

I've mainly worked on Windows, so I'm quite unfamiliar with less common issues under Linux.

Here's the error I'm getting when dub tries to link my application:

/usr/bin/ld: .dub/obj/pixelperfectengine_pixelperfecteditor.o: undefined reference to symbol 'inflateEnd'
//lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
/usr/bin/ldc2 failed with exit code 1.

I've an image handling library as a dependency, which is required for the application, and it (obviously) uses zlib for *.png compression/decompression. I've installed zlib1g-dev for Ubuntu, but did not fix my issues, and the same exact code compiles without any issues under Windows.

Upvotes: 0

Views: 2004

Answers (3)

Geod24
Geod24

Reputation: 893

You need to link in zlib, as mentioned before.

I would recommend to do so via the "libs" array (see this page: https://dub.pm/package-format-json.html). The advantage of using libs over lflags is that libs will try to use pkg-config, which is a generic way to get linker / compile flags for C[++] libraries on POSIX. It works on Linux and Mac OSX. If pkg-config is not found, dub will just default to do what lflags would do in the first place.

Here's an example from my own project: https://github.com/Geod24/libsodiumd/blob/9b397645e2fc3ca502acb58e1b4631d3faf094e2/dub.json

Upvotes: 0

Panke
Panke

Reputation: 186

It's probably enough to add -lz to the lflags in your dub file.

Upvotes: 0

Employed Russian
Employed Russian

Reputation: 213375

/lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line

This error is telling you that you must add -lz to command line. I don't know what dub is, but somehow you must convince it to add -lz to the link command it constructs.

Upvotes: 0

Related Questions