[llvm-dev] Unable to build static binary
Danie Grobbelaar via llvm-dev
llvm-dev at lists.llvm.org
Fri May 7 19:50:12 PDT 2021
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210508/032a66d6/attachment.html>
More information about the llvm-dev
mailing list