[llvm-dev] Unable to build static binary

pawel k. via llvm-dev llvm-dev at lists.llvm.org
Mon May 10 23:24:13 PDT 2021


Here my notes are:
-Others were getting somewhere else such errors too and were equally puzzled
-I wonder if llvm.lld could be even nicer in saying something like:
"When trying to statically link <binaryname> with options <options causing
staticlink>, dynamic object <dynobjname> was found on a chain due to
options <either explicit so mention or offending -llibname etc>, please
consider switching to dynamic link with <options that would cause dynamic
linking> or using static version of <dynobjname>"
-If above is too much, entry in documentation and url to article could be
good enough as second line of error message.

Pawel

sob., 8.05.2021, 04:50 użytkownik Danie Grobbelaar via llvm-dev <
llvm-dev at lists.llvm.org> napisał:

> I'm currently having issues trying to rebuild one of my projects with an
> updated version of LLVM. This project generates a statically linked binary.
>
> My previous build used llvm-10.0.0 and I could build the binary without
> any issues. When I checked out HEAD a few weeks ago (commit 82fbc5d) and
> tried a build, it failed with the following linking error:
>
> /usr/bin/c++  -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall
> -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wno-missing-field-initializers -pedantic -Wno-long-long
> -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess
> -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type
> -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment
> -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common
> -Woverloaded-virtual -fno-strict-aliasing -O3 -O3 -DNDEBUG  -static
> -Wl,-rpath-link,/home/danie/nett-testing/tmp/llvm-project/build/./lib
> -Wl,-O3 -Wl,--gc-sections *<source files>* -o *<binary name>*
> -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVMSupport.a  -lpthread
> -static-libgcc  -static-libstdc++  lib/libclangTooling.a
> lib/libclangBasic.a  lib/libclangASTMatchers.a  lib/libclangFormat.a
> lib/libclangToolingInclusions.a  lib/libclangFrontend.a
> lib/libclangDriver.a  lib/libclangParse.a  lib/libclangSerialization.a
> lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAnalysis.a
> lib/libclangASTMatchers.a  lib/libclangAST.a  lib/libclangToolingCore.a
> lib/libclangRewrite.a  lib/libclangLex.a  lib/libclangBasic.a
> lib/libLLVMOption.a  lib/libLLVMFrontendOpenMP.a
> lib/libLLVMTransformUtils.a  lib/libLLVMAnalysis.a
> lib/libLLVMProfileData.a  lib/libLLVMObject.a  lib/libLLVMBitReader.a
> lib/libLLVMCore.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a
> lib/libLLVMMCParser.a  lib/libLLVMMC.a  lib/libLLVMDebugInfoCodeView.a
> lib/libLLVMTextAPI.a  lib/libLLVMBinaryFormat.a  lib/libLLVMSupport.a
> -lrt  -ldl  -lpthread  -lm  /usr/lib/x86_64-linux-gnu/libz.so
> /usr/lib/x86_64-linux-gnu/libtinfo.so  lib/libLLVMDemangle.a && :
> /usr/bin/ld: attempted static link of dynamic object
> `/usr/lib/x86_64-linux-gnu/libz.so'
>
> I haven't changed my CMakeLists.txt file, and I'm lost as to how to fix
> this issue. Any help would be appreciated. For reference, my CMakeLists.txt
> file as as follows:
>
> --- BEGIN CMakeLists.txt ---
> set(LLVM_LINK_COMPONENTS support)
>
> add_clang_executable(mybinary
>     <source files>
>     )
>
> set (GCC_COMPILE_FLAGS "-O3")
> set (GCC_LINK_FLAGS "-static")
> set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILER_FLAGS}")
> set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}")
>
> target_link_libraries(mybinary
>     PRIVATE
>     -static-libgcc
>     -static-libstdc++
>     clangTooling
>     clangBasic
>     clangASTMatchers
>     )
> --- END CMakeLists.txt ---
>
> Kind regards and thank you in advance,
> Danie Grobbelaar
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210511/5c3f78ce/attachment.html>


More information about the llvm-dev mailing list