Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Build failed with undefined reference to 'crc32' on Ubuntu Linux #25

Closed
dougpuob opened this issue Aug 25, 2019 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@dougpuob
Copy link
Owner

Even I built with -lz option, but it still showed the following error.

  • Compression.cpp: undefined reference to `compressBound'
  • Compression.cpp: undefined reference to `compress2'
  • undefined reference to `uncompress'
  • undefined reference to `crc32'

Error Message

[ 35%] Linking CXX executable Output/cppnamelint
/usr/bin/cmake -E cmake_link_script CMakeFiles/cppnamelint.dir/link.txt --verbose=1
/usr/bin/g++-8  -frtti -lz -ltinfo -O3 -DNDEBUG   CMakeFiles/cppnamelint.dir/Source/Main.cpp.o CMakeFiles/cppnamelint.dir/Source/Detection.cpp.o CMakeFiles/cppnamelint.dir/Source/Common.cpp.o CMakeFiles/cppnamelint.dir/Source/Config.cpp.o CMakeFiles/cppnamelint.dir/Source/MyFactory.cpp.o CMakeFiles/cppnamelint.dir/Source/MyAstVisitor.cpp.o CMakeFiles/cppnamelint.dir/Source/MyAstConsumer.cpp.o CMakeFiles/cppnamelint.dir/Source/Test/TestConfig.cpp.o CMakeFiles/cppnamelint.dir/Source/Test/TestDetection.cpp.o  -o Output/cppnamelint  -L/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib -Wl,-rpath,/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib Module/docopt.cpp/libdocopt.a lib/libgtest.a lib/libgtest_main.a -lclangAnalysis -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor -lLLVMAArch64AsmParser -lLLVMAArch64AsmPrinter -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Disassembler -lLLVMAArch64Info -lLLVMAArch64Utils -lLLVMAggressiveInstCombine -lLLVMAMDGPUAsmParser -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUDisassembler -lLLVMAMDGPUInfo -lLLVMAMDGPUUtils -lLLVMAnalysis -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMDisassembler -lLLVMARMInfo -lLLVMARMUtils -lLLVMAsmParser -lLLVMAsmPrinter -lLLVMBinaryFormat -lLLVMBitReader -lLLVMBitWriter -lLLVMBPFAsmParser -lLLVMBPFAsmPrinter -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFDisassembler -lLLVMBPFInfo -lLLVMCodeGen -lLLVMCore -lLLVMCoroutines -lLLVMCoverage -lLLVMDebugInfoCodeView -lLLVMDebugInfoDWARF -lLLVMDebugInfoMSF -lLLVMDebugInfoPDB -lLLVMDemangle -lLLVMDlltoolDriver -lLLVMExecutionEngine -lLLVMFuzzMutate -lLLVMGlobalISel -lLLVMHexagonAsmParser -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonDisassembler -lLLVMHexagonInfo -lLLVMInstCombine -lLLVMInstrumentation -lLLVMInterpreter -lLLVMipo -lLLVMIRReader -lLLVMLanaiAsmParser -lLLVMLanaiAsmPrinter -lLLVMLanaiCodeGen -lLLVMLanaiDesc -lLLVMLanaiDisassembler -lLLVMLanaiInfo -lLLVMLibDriver -lLLVMLineEditor -lLLVMLinker -lLLVMLTO -lLLVMMC -lLLVMMCDisassembler -lLLVMMCJIT -lLLVMMCParser -lLLVMMipsAsmParser -lLLVMMipsAsmPrinter -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsDisassembler -lLLVMMipsInfo -lLLVMMIRParser -lLLVMMSP430AsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMNVPTXAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMObjCARCOpts -lLLVMObject -lLLVMObjectYAML -lLLVMOption -lLLVMOrcJIT -lLLVMPasses -lLLVMPowerPCAsmParser -lLLVMPowerPCAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCDisassembler -lLLVMPowerPCInfo -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSparcAsmParser -lLLVMSparcAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcDisassembler -lLLVMSparcInfo -lLLVMSupport -lLLVMSymbolize -lLLVMSystemZAsmParser -lLLVMSystemZAsmPrinter -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZDisassembler -lLLVMSystemZInfo -lLLVMTableGen -lLLVMTarget -lLLVMTestingSupport -lLLVMTransformUtils -lLLVMVectorize -lLLVMWindowsManifest -lLLVMX86AsmParser -lLLVMX86AsmPrinter -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Disassembler -lLLVMX86Info -lLLVMX86Utils -lLLVMXCoreAsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreDisassembler -lLLVMXCoreInfo -lLLVMXRay -lLTO -lclangParse -lclangSerialization -lclangDriver -lclangIndex -lclangSema -lclangAnalysis -lclangAST -lclangFrontend -lclangEdit -lclangLex -lclangBasic -lLLVMSupport -lLLVMCore -lLLVMMC lib/libgtest.a -lpthread -lclangARCMigrate -lclangASTMatchers -lclangCodeGen -lclangCrossTU -lclangDynamicASTMatchers -lclangFormat -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor -lLLVMAArch64AsmParser -lLLVMAArch64AsmPrinter -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Disassembler -lLLVMAArch64Info -lLLVMAArch64Utils -lLLVMAggressiveInstCombine -lLLVMAMDGPUAsmParser -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUDisassembler -lLLVMAMDGPUInfo -lLLVMAMDGPUUtils -lLLVMAnalysis -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMDisassembler -lLLVMARMInfo -lLLVMARMUtils -lLLVMAsmParser -lLLVMAsmPrinter -lLLVMBinaryFormat -lLLVMBitReader -lLLVMBitWriter -lLLVMBPFAsmParser -lLLVMBPFAsmPrinter -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFDisassembler -lLLVMBPFInfo -lLLVMCodeGen -lLLVMCoroutines -lLLVMCoverage -lLLVMDebugInfoCodeView -lLLVMDebugInfoDWARF -lLLVMDebugInfoMSF -lLLVMDebugInfoPDB -lLLVMDemangle -lLLVMDlltoolDriver -lLLVMExecutionEngine -lLLVMFuzzMutate -lLLVMGlobalISel -lLLVMHexagonAsmParser -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonDisassembler -lLLVMHexagonInfo -lLLVMInstCombine -lLLVMInstrumentation -lLLVMInterpreter -lLLVMipo -lLLVMIRReader -lLLVMLanaiAsmParser -lLLVMLanaiAsmPrinter -lLLVMLanaiCodeGen -lLLVMLanaiDesc -lLLVMLanaiDisassembler -lLLVMLanaiInfo -lLLVMLibDriver -lLLVMLineEditor -lLLVMLinker -lLLVMLTO -lLLVMMCDisassembler -lLLVMMCJIT -lLLVMMCParser -lLLVMMipsAsmParser -lLLVMMipsAsmPrinter -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsDisassembler -lLLVMMipsInfo -lLLVMMIRParser -lLLVMMSP430AsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMNVPTXAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMObjCARCOpts -lLLVMObject -lLLVMObjectYAML -lLLVMOption -lLLVMOrcJIT -lLLVMPasses -lLLVMPowerPCAsmParser -lLLVMPowerPCAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCDisassembler -lLLVMPowerPCInfo -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSparcAsmParser -lLLVMSparcAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcDisassembler -lLLVMSparcInfo -lLLVMSymbolize -lLLVMSystemZAsmParser -lLLVMSystemZAsmPrinter -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZDisassembler -lLLVMSystemZInfo -lLLVMTableGen -lLLVMTarget -lLLVMTestingSupport -lLLVMTransformUtils -lLLVMVectorize -lLLVMWindowsManifest -lLLVMX86AsmParser -lLLVMX86AsmPrinter -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Disassembler -lLLVMX86Info -lLLVMX86Utils -lLLVMXCoreAsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreDisassembler -lLLVMXCoreInfo -lLLVMXRay -lLTO 
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, int)':
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x2f): undefined reference to `compressBound'
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x52): undefined reference to `compress2'
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::uncompress(llvm::StringRef, char*, unsigned long&)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefEPcRm+0x2a): undefined reference to `uncompress'
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::crc32(llvm::StringRef)':
Compression.cpp:(.text._ZN4llvm4zlib5crc32ENS_9StringRefE+0xc): undefined reference to `crc32'
collect2: error: ld returned 1 exit status
CMakeFiles/cppnamelint.dir/build.make:306: recipe for target 'Output/cppnamelint' failed
make[2]: *** [Output/cppnamelint] Error 1
make[2]: Leaving directory '/home/dougpuob/my-data/my-repo/cppnamelint.git/Build/linux'
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/cppnamelint.dir/all' failed
make[1]: *** [CMakeFiles/cppnamelint.dir/all] Error 2
make[1]: Leaving directory '/home/dougpuob/my-data/my-repo/cppnamelint.git/Build/linux'
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

image

@dougpuob dougpuob added the bug Something isn't working label Aug 25, 2019
@dougpuob dougpuob self-assigned this Aug 25, 2019
@dougpuob dougpuob changed the title [Bug] Build failed with undefined reference to `compress2' on Ubuntu Linux [Bug] Build failed with undefined reference to 'crc32' on Ubuntu Linux Aug 25, 2019
@dougpuob
Copy link
Owner Author

dougpuob commented Aug 25, 2019

$ ldconfig -v 2>/dev/null | grep -v ^$'\t'

/usr/lib/x86_64-linux-gnu/libfakeroot:
/usr/local/lib:
/lib/x86_64-linux-gnu:
/usr/lib/x86_64-linux-gnu:                                    <--**HERE**
/lib32:
/usr/lib32:
/lib:
/usr/lib:

locate command to find libz

 $ locate libz
/lib/x86_64-linux-gnu/libz.so.1
/lib/x86_64-linux-gnu/libz.so.1.2.11
/usr/lib/jvm/java-11-openjdk-amd64/lib/libzip.so
/usr/lib/x86_64-linux-gnu/libz.a                              <--**HERE**
/usr/lib/x86_64-linux-gnu/libz.so
/usr/lib/x86_64-linux-gnu/libzeitgeist-2.0.so.0
/usr/lib/x86_64-linux-gnu/libzeitgeist-2.0.so.0.0.0
/usr/lib/x86_64-linux-gnu/libzmq.so.5
/usr/lib/x86_64-linux-gnu/libzmq.so.5.1.5
/usr/lib/x86_64-linux-gnu/libzstd.so.1
/usr/lib/x86_64-linux-gnu/libzstd.so.1.3.3
/usr/lib/x86_64-linux-gnu/libzvbi-chains.so.0
/usr/lib/x86_64-linux-gnu/libzvbi-chains.so.0.0.0
/usr/lib/x86_64-linux-gnu/libzvbi.so.0
/usr/lib/x86_64-linux-gnu/libzvbi.so.0.13.2

readelf -a to find functions

  • crc32
  • compress2
  • uncompress
  • compressBound
-------------------------------------------------------------------------------------
readelf -a /usr/lib/x86_64-linux-gnu/libz.a | grep crc32
File: /usr/lib/x86_64-linux-gnu/libz.a(crc32.o)
     2: 0000000000000000  1107 FUNC    LOCAL  DEFAULT    1 crc32_little
     4: 0000000000000460   505 FUNC    LOCAL  DEFAULT    1 crc32_combine_
    13: 0000000000000670    19 FUNC    GLOBAL DEFAULT    1 crc32_z
    14: 0000000000000690    19 FUNC    GLOBAL DEFAULT    1 crc32
    15: 00000000000006b0     5 FUNC    GLOBAL DEFAULT    1 crc32_combine
    16: 00000000000006c0     5 FUNC    GLOBAL DEFAULT    1 crc32_combine64
    22: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND crc32
    44: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND crc32

-------------------------------------------------------------------------------------
readelf -s /usr/lib/x86_64-linux-gnu/libz.a | grep compress2
     8: 0000000000000000   311 FUNC    GLOBAL DEFAULT    1 compress2
     8: 0000000000000000   447 FUNC    GLOBAL DEFAULT    1 uncompress2

-------------------------------------------------------------------------------------
readelf -s /usr/lib/x86_64-linux-gnu/libz.a | grep uncompress 
     8: 0000000000000000   447 FUNC    GLOBAL DEFAULT    1 uncompress2
    14: 00000000000001c0   445 FUNC    GLOBAL DEFAULT    1 uncompress

-------------------------------------------------------------------------------------
readelf -s /usr/lib/x86_64-linux-gnu/libz.a | grep compressBound
    15: 0000000000000280    30 FUNC    GLOBAL DEFAULT    1 compressBound

@dougpuob
Copy link
Owner Author

Move libz to the to the last of target_link_libraries() function.

if(WIN32)
    set(EXTERNAL_LIB Version)
elseif(UNIX AND NOT APPLE)
    set(EXTERNAL_LIB z tinfo)
elseif(APPLE)
    set(EXTERNAL_LIB z ncurses)
endif()

target_link_libraries(
    cppnamelint
    docopt
   ...
    ${EXTERNAL_LIB}   <-- **HERE** put this to the lowest
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant