atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

/usr/bin/ld.gold: error: cannot find -lclang #238

Closed andre2007 closed 4 years ago

andre2007 commented 4 years ago

I tried to install dpp within a dockerfile, but it fails with:

/usr/bin/ld.gold: error: cannot find -lclang
/root/.dub/packages/libclang-0.2.6/libclang/source/clang/package.d:716: error: undefined reference to 'clang_getNumArgTypes'
/root/.dub/packages/libclang-0.2.6/libclang/source/clang/package.d:712: error: undefined reference to 'clang_getArgType'
/root/.dub/packages/libclang-0.2.6/libclang/source/clang/package.d:220: error: undefined reference to 'clang_visitChildren'
/root/.dub/packages/libclang-0.2.6/libclang/source/clang/package.d:220: error: undefined reference to 'clang_visitChildren'
package.d:40: error: undefined reference to 'clang_createIndex'
package.d:66: error: undefined reference to 'clang_getNumDiagnostics'

the dockerfile looks like this:

FROM dlang2/ldc-ubuntu:1.19.0

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y libclang-6.0-dev libgtk-3-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN dub fetch dpp && dub build dpp

In the readme I can only find the package dependency libclang-6.0-dev. What else do I miss?

atilaneves commented 4 years ago

Whatever is going on, it's not an ld.gold problem, since I exclusively use that linker.

I don't know where ubuntu installs libclang. From my experiences with the Travis Ubuntu container, it seems to be in /usr/local/clang-7.0.0/lib (adjust as necessary for the version number, obviously).

andre2007 commented 4 years ago

For docker image dlang2/ldc-ubuntu the path is actually /usr/lib/clang/6.0.0. I tried to create a symbolic link to check whether the error disappear ln -s /usr/lib/clang/6.0.0 /usr/local/clang-6.0.0 but still, the same error while trying to build dpp.

BorisCarvajal commented 4 years ago

I had a similar problem in Gentoo (ld cannot find -lclang) and for some reason (bug?) dub doesn't pass DFLAGS to dmd in the linking phase, however it will pass it if you are using --compiler=ldc2. So I've resorted to setting the CC env. variable.

The following commands worked in my case:

CC=clang dub build // clang auto detects the library CC="gcc -L/usr/lib/llvm/9/lib64/" dub build DFLAGS="-L=-L/usr/lib/llvm/9/lib64/" dub build --compiler=ldc2 // with the ldc2 switch DFLAGS works

andre2007 commented 4 years ago

@BorisCarvajal thank you very much.