silkeh / docker-clang

Dockerfiles for Clang and LLVM
European Union Public License 1.2
100 stars 30 forks source link

Compiling with LTO Fails #11

Closed qak closed 2 years ago

qak commented 3 years ago

Compiling a program fails when enabling link-time optimisations (LTO). The problem can be reproduced by running the following command in the Docker image:

$ echo "int main(){}" >> main.cpp; clang++ main.cpp -flto=thin
/usr/bin/ld: /usr/local/bin/../lib/LLVMgold.so: error loading plugin: /usr/local/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory

I unfortunately have no idea what should be done to fix this issue.

bensuperpc commented 3 years ago

On these binaries, clang does not have the libraries for this :/ The only solutions are either to find binaries with these libraries, or to compile by yourself. The options, -flto=thin is not necessarily essential

I am doing PR to update repos and docker images, i will try to make a docker image with all options

bensuperpc commented 3 years ago

Compiling a program fails when enabling link-time optimisations (LTO). The problem can be reproduced by running the following command in the Docker image:

$ echo "int main(){}" >> main.cpp; clang++ main.cpp -flto=thin
/usr/bin/ld: /usr/local/bin/../lib/LLVMgold.so: error loading plugin: /usr/local/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory

I unfortunately have no idea what should be done to fix this issue.

You can use Dockcross if you want LTO: https://github.com/dockcross/dockcross (linux-x64-clang)

silkeh commented 2 years ago

This should now work for all buster and bullseye based images (i.e. 7 or higher).