<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="auto"><div>Thank you for that. </div><div>Using it, I managed to get the static versions of zlib and libtinfo with the following:</div><div> set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")</div><div><div> find_package(ZLIB REQUIRED)</div></div><div> find_library(TINFO "libtinfo" REQUIRED)</div><div><br></div><div> target_link_libraries(prog</div><div> PRIVATE</div><div> clangTooling clangBasic clangASTMatchers</div><div> -static-libgcc -static-libstdc++ -static</div><div> ${ZLIB} ${TINFO}</div><div> )</div><div><br></div><div>However I now have the issue where I can't seem to remove the link to the dynamic versions of the libraries. Note the following output:</div><div><br></div><div><div> <font face="monospace">/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 -Wl,-rpath-link,/home/danie/nett-testing/tmp/llvm-project/build/./lib -Wl,-O3 -Wl,--gc-sections <b><program files></b> -o <b><output></b> -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMSupport.a -lpthread lib/libclangTooling.a lib/libclangBasic.a lib/libclangASTMatchers.a -static-libgcc -static-libstdc++ -static <font color="#38761d"><b>/usr/lib/x86_64-linux-gnu/libz.a /usr/lib/x86_64-linux-gnu/libtinfo.a</b> </font> 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 <b><font color="#ff0000">/usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libtinfo.so</font></b> lib/libLLVMDemangle.a && :</font></div><div><font face="monospace">/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libz.so'</font></div></div><div><br></div><div>Is there a way to let cmake know which libraries I want?</div><div><br></div><div>Kind regards and thank you in advance,</div><div>Danie Grobbelaar</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 11 May 2021, 10:17 Fangrui Song, <<a href="mailto:maskray@google.com" target="_blank">maskray@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2021-05-08, Danie Grobbelaar via llvm-dev wrote:<br>
>I'm currently having issues trying to rebuild one of my projects with an<br>
>updated version of LLVM. This project generates a statically linked binary.<br>
><br>
>My previous build used llvm-10.0.0 and I could build the binary without any<br>
>issues. When I checked out HEAD a few weeks ago (commit 82fbc5d) and tried<br>
>a build, it failed with the following linking error:<br>
><br>
>/usr/bin/c++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall<br>
>-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual<br>
>-Wno-missing-field-initializers -pedantic -Wno-long-long<br>
>-Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess<br>
>-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type<br>
>-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment<br>
>-fdiagnostics-color -ffunction-sections -fdata-sections -fno-common<br>
>-Woverloaded-virtual -fno-strict-aliasing -O3 -O3 -DNDEBUG -static<br>
>-Wl,-rpath-link,/home/danie/nett-testing/tmp/llvm-project/build/./lib<br>
>-Wl,-O3 -Wl,--gc-sections *<source files>* -o *<binary name>*<br>
>-Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMSupport.a -lpthread<br>
>-static-libgcc -static-libstdc++ lib/libclangTooling.a<br>
>lib/libclangBasic.a lib/libclangASTMatchers.a lib/libclangFormat.a<br>
>lib/libclangToolingInclusions.a lib/libclangFrontend.a<br>
>lib/libclangDriver.a lib/libclangParse.a lib/libclangSerialization.a<br>
>lib/libclangSema.a lib/libclangEdit.a lib/libclangAnalysis.a<br>
>lib/libclangASTMatchers.a lib/libclangAST.a lib/libclangToolingCore.a<br>
>lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a<br>
>lib/libLLVMOption.a lib/libLLVMFrontendOpenMP.a<br>
>lib/libLLVMTransformUtils.a lib/libLLVMAnalysis.a<br>
>lib/libLLVMProfileData.a lib/libLLVMObject.a lib/libLLVMBitReader.a<br>
>lib/libLLVMCore.a lib/libLLVMRemarks.a lib/libLLVMBitstreamReader.a<br>
>lib/libLLVMMCParser.a lib/libLLVMMC.a lib/libLLVMDebugInfoCodeView.a<br>
>lib/libLLVMTextAPI.a lib/libLLVMBinaryFormat.a lib/libLLVMSupport.a<br>
>-lrt -ldl -lpthread -lm /usr/lib/x86_64-linux-gnu/libz.so<br>
>/usr/lib/x86_64-linux-gnu/libtinfo.so lib/libLLVMDemangle.a && :<br>
>/usr/bin/ld: attempted static link of dynamic object<br>
>`/usr/lib/x86_64-linux-gnu/libz.so'<br>
><br>
>I haven't changed my CMakeLists.txt file, and I'm lost as to how to fix<br>
>this issue. Any help would be appreciated. For reference, my CMakeLists.txt<br>
>file as as follows:<br>
><br>
>--- BEGIN CMakeLists.txt ---<br>
>set(LLVM_LINK_COMPONENTS support)<br>
><br>
>add_clang_executable(mybinary<br>
> <source files><br>
> )<br>
><br>
>set (GCC_COMPILE_FLAGS "-O3")<br>
>set (GCC_LINK_FLAGS "-static")<br>
>set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILER_FLAGS}")<br>
>set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS}")<br>
><br>
>target_link_libraries(mybinary<br>
> PRIVATE<br>
> -static-libgcc<br>
> -static-libstdc++<br>
> clangTooling<br>
> clangBasic<br>
> clangASTMatchers<br>
> )<br>
>--- END CMakeLists.txt ---<br>
><br>
>Kind regards and thank you in advance,<br>
>Danie Grobbelaar<br>
<br>
This can be an issue of the CMake module called by find_package(ZLIB)<br>
<a href="https://stackoverflow.com/questions/58347250/how-to-find-static-version-of-zlib-in-cmake" rel="noreferrer noreferrer" target="_blank">https://stackoverflow.com/questions/58347250/how-to-find-static-version-of-zlib-in-cmake</a><br>
<br>
As a workaround, -DLLVM_ENABLE_ZLIB=off, but some zlib features will be<br>
disabled (clang -gz, ld.lld's ability to read/write compressed debug sections).<br>
</blockquote></div></div></div>
</div></div></div></div>