dlang / dub

Package and build management system for D
MIT License
674 stars 230 forks source link

resolveLibs does not take into account druntime or phobos dependencies #864

Open WebDrake opened 8 years ago

WebDrake commented 8 years ago

The current resolveLibs function translates specified library dependencies into appropriate linker flags. However, it does not account for the possibility that the available druntime or phobos might have dynamically-linked dependencies which must also be referenced at link-time.

Presumably it is assumed that druntime and phobos' dependencies are statically linked into the library, but this is not a safe assumption.

Example: the Debian/Ubuntu ldc packages link dynamically against zlib. Therefore, any program that uses etc.c.zlib will fail to link if -lz is not provided explicitly as a linker flag. See: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/31256/ for an example of issues caused by this.

WebDrake commented 8 years ago

Minimal example that will show the issue on Ubuntu or Debian. To reproduce:

import etc.c.zlib;

void main()
{
    get_crc_table();
}

dub build will then result in a linker error:

.dub/obj/.dub/build/application-debug-linux.posix-x86_64-ldc_0-7D996CB3B020EA902F20F19512139E21/dub-lflags.o: In function `_Dmain':
source/app.d:5: undefined reference to `get_crc_table'

Adding "lflags": ["-lz"] to the dub.json file (or lflags "-lz" for dub.sdl) will allow the program to build correctly.

s-ludwig commented 7 years ago

Appears like this is fixed with recent LDC versions. Can you confirm?

But to me it generally seems like this should be something that is controlled by the compiler configuration file. It would simply be a relatively costly dependency having to maintain this in sync with each compiler and compiler version within DUB.