I'm trying to link together:
libFuzzer.a, compiled with clang++-5.0 and -std=c++11
my fuzz driver, compiled with clang++-5.0 and -std=c++11 -stdlib=libc++
libcurl, compiled with clang-5.0
Specifically, this linker command is being executed:
/bin/bash ../../libtool --silent --tag=CXX --mode=link clang++-5.0 -I../../include -I../../lib -I../../lib -I../../tests/fuzz -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp -std=c++11 -stdlib=libc++ -o curl_fuzzer curl_fuzzer-curl_fuzzer.o ../../lib/libcurl.la /root/checkouts/Fuzzer/libFuzzer.a -lssh2 -lssl -lcrypto -lssl -lcrypto -lz -lpthread -lm
Executing this command outputs the following:
/bin/bash ../../libtool --silent --tag=CXX --mode=link clang++-5.0 -I../../include -I../../lib -I../../lib -I../../tests/fuzz -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp -std=c++11 -stdlib=libc++ -o curl_fuzzer curl_fuzzer-curl_fuzzer.o ../../lib/libcurl.la /root/checkouts/Fuzzer/libFuzzer.a -lssh2 -lssl -lcrypto -lssl -lcrypto -lz -lpthread -lm > /tmp/cat.txt 2>&1; head -20 /tmp/cat.txt
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `fuzzer::FileToVector(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, bool)':
/root/checkouts/Fuzzer/./FuzzerIO.cpp:34: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
/root/checkouts/Fuzzer/./FuzzerIO.cpp:40: undefined reference to `std::istream::seekg(long, std::_Ios_Seekdir)'
/root/checkouts/Fuzzer/./FuzzerIO.cpp:41: undefined reference to `std::istream::tellg()'
/root/checkouts/Fuzzer/./FuzzerIO.cpp:47: undefined reference to `std::istream::seekg(long, std::_Ios_Seekdir)'
/root/checkouts/Fuzzer/./FuzzerIO.cpp:49: undefined reference to `std::istream::read(char*, long)'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `~basic_ifstream':
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/fstream:534: undefined reference to `VTT for std::basic_ifstream<char, std::char_traits<char> >'
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/fstream:534: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `~basic_ios':
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/basic_ios.h:282: undefined reference to `std::ios_base::~ios_base()'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `~basic_ifstream':
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/fstream:534: undefined reference to `VTT for std::basic_ifstream<char, std::char_traits<char> >'
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/fstream:534: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `~basic_ios':
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/basic_ios.h:282: undefined reference to `std::ios_base::~ios_base()'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `fuzzer::FileToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/root/checkouts/Fuzzer/./FuzzerIO.cpp:54: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
/root/checkouts/Fuzzer/libFuzzer.a(FuzzerIO.o): In function `~basic_ifstream':
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/fstream:534: undefined reference to `VTT for std::basic_ifstream<char, std::char_traits<char> >'
<snip>
I've tried doing the following to fix this:
Adding -lc++ - doesn't do anything
Adding -lc++abi - doesn't do anything
It feels like I'm missing something obvious but I'm not sure what...
My installation of clang-5.0 comes from clang-5.0/kali-rolling.
You have compiled part of your code with libstdc++ and part with libc++. When you link them together (using libc++), the parts that have references to libstdc++ don't get resolved.
For example, std::__cxx11::basic_string is definitely a libstdc++ symbol.
Looks like for whatever reason kali's version of clang-5.0 doesn't link binaries with libc++ properly. I tested the same code with google's ossfuzz version of clang (clang-6.0) and everything linked together successfully.
The OP mentioned (2017):
Looks like for whatever reason kali's version of clang-5.0 doesn't link binaries with libc++ properly.
I tested the same code with google's ossfuzz version of clang (clang-6.0) and everything linked together successfully.
At the time, libstdc++ was needed.
But now, from the current LibFuzzer documentation (March 2021)
Recent versions of Clang (starting from 6.0) include libFuzzer, and no extra installation is necessary.
As an illustration of that new ("new" meaning "post CLang 5") usage, Git 2.31.1 (Q1 2021), references the same LibFuzzer 11.0 documentation section:
See commit 68b5c3a (08 Mar 2021) by Andrzej Hunt (ahunt).
(Merged by Junio C Hamano -- gitster -- in commit af10702, 19 Mar 2021)
Makefile: update 'make fuzz-all' docs to reflect modern clang
Signed-off-by: Andrzej Hunt
Clang no longer produces a libFuzzer.a.
Instead, you can include libFuzzer by using -fsanitize=fuzzer.
Therefore we should use that in the example command for building fuzzers.
We also add -fsanitize=fuzzer-no-link to the CFLAGS to ensure that all the required instrumentation is added when compiling git 1, and remove -fsanitize-coverage=trace-pc-guard as it is deprecated.
I happen to have tested with LLVM 11 - however -fsanitize=fuzzer appears to work in a wide range of reasonably modern clangs.
(On my system: what used to be libFuzzer.a now lives under the following path, which is tricky albeit not impossible for a novice such as myself to find:
/usr/lib64/clang/11.0.0/lib/linux/libclang_rt.fuzzer-x86_64.a )
Related
I've tried with many versions of llvm, installed, uninstalled, the original tutorial code and the one with folders and a make file from: https://github.com/ghaiklor/llvm-kaleidoscope
(with adjustments).
The latest iteration and the best solution so far is with the original code and latest llvm:
https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl03.html
clang++ -g -O3 3.cpp -I /lib/llvm-16/include/ `llvm-config -std=c++14 --cxxflags --ldflags --system-libs --libs all --version` -v -o 3.exe
It seems it compiles, but the linker complains for "undefined references" to probably all llvm files.
llvm-config reports a location of the libraries, in /usr/lib/... as shown below; I found the libs also in root /lib/llvm-16/lib if that could cause some conflict, but I doubt that.
clang++ --version
Ubuntu clang version 16.0.0 (++20230109052936+64f06dda87cf-1~exp1~20230109173029.503)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
llvm-config --libdir
/usr/lib/llvm-16/lib
ls /usr/lib/llvm-16/lib
LLVMPolly.so libLLVMDlltoolDriver.a libLLVMPowerPCCodeGen.a
LLVMgold.so libLLVMExecutionEngine.a libLLVMPowerPCDesc.a
clang libLLVMExegesis.a libLLVMPowerPCDisassembler.a
cmake libLLVMExegesisAArch64.a libLLVMPowerPCInfo.a
libLLVM-16.0.0.so libLLVMExegesisMips.a libLLVMProfileData.a
libLLVM-16.0.0.so.1 libLLVMExegesisPowerPC.a libLLVMRISCVAsmParser.a
libLLVM-16.so libLLVMExegesisX86.a libLLVMRISCVCodeGen.a
libLLVM-16.so.1 libLLVMExtensions.a libLLVMRISCVDesc.a
libLLVM.so libLLVMFileCheck.a libLLVMRISCVDisassembler.a
libLLVMAArch64AsmParser.a libLLVMFrontendHLSL.a libLLVMRISCVInfo.a
libLLVMAArch64CodeGen.a libLLVMFrontendOpenACC.a libLLVMRISCVTargetMCA.a
libLLVMAArch64Desc.a libLLVMFrontendOpenMP.a libLLVMRemarks.a
libLLVMAArch64Disassembler.a libLLVMFuzzMutate.a libLLVMRuntimeDyld.a
libLLVMAArch64Info.a libLLVMFuzzerCLI.a libLLVMScalarOpts.a
libLLVMAArch64Utils.a libLLVMGlobalISel.a libLLVMSelectionDAG.a
libLLVMAMDGPUAsmParser.a libLLVMHexagonAsmParser.a libLLVMSparcAsmParser.a
libLLVMAMDGPUCodeGen.a libLLVMHexagonCodeGen.a libLLVMSparcCodeGen.a
libLLVMAMDGPUDesc.a libLLVMHexagonDesc.a libLLVMSparcDesc.a
libLLVMAMDGPUDisassembler.a libLLVMHexagonDisassembler.a libLLVMSparcDisassembler.a
libLLVMAMDGPUInfo.a libLLVMHexagonInfo.a libLLVMSparcInfo.a
libLLVMAMDGPUTargetMCA.a libLLVMIRPrinter.a libLLVMSupport.a
libLLVMAMDGPUUtils.a libLLVMIRReader.a libLLVMSymbolize.a
libLLVMARMAsmParser.a libLLVMInstCombine.a libLLVMSystemZAsmParser.a
libLLVMARMCodeGen.a libLLVMInstrumentation.a libLLVMSystemZCodeGen.a
libLLVMARMDesc.a libLLVMInterfaceStub.a libLLVMSystemZDesc.a
libLLVMARMDisassembler.a libLLVMInterpreter.a libLLVMSystemZDisassembler.a
libLLVMARMInfo.a libLLVMJITLink.a libLLVMSystemZInfo.a
libLLVMARMUtils.a libLLVMLTO.a libLLVMTableGen.a
libLLVMAVRAsmParser.a libLLVMLanaiAsmParser.a libLLVMTableGenGlobalISel.a
libLLVMAVRCodeGen.a libLLVMLanaiCodeGen.a libLLVMTarget.a
libLLVMAVRDesc.a libLLVMLanaiDesc.a libLLVMTargetParser.a
libLLVMAVRDisassembler.a libLLVMLanaiDisassembler.a libLLVMTextAPI.a
libLLVMAVRInfo.a libLLVMLanaiInfo.a libLLVMTransformUtils.a
libLLVMAggressiveInstCombine.a libLLVMLibDriver.a libLLVMVEAsmParser.a
libLLVMAnalysis.a libLLVMLineEditor.a libLLVMVECodeGen.a
libLLVMAsmParser.a libLLVMLinker.a libLLVMVEDesc.a
libLLVMAsmPrinter.a libLLVMM68kAsmParser.a libLLVMVEDisassembler.a
libLLVMBOLTCore.a libLLVMM68kCodeGen.a libLLVMVEInfo.a
libLLVMBOLTPasses.a libLLVMM68kDesc.a libLLVMVectorize.a
libLLVMBOLTProfile.a libLLVMM68kDisassembler.a libLLVMWebAssemblyAsmParser.a
libLLVMBOLTRewrite.a libLLVMM68kInfo.a libLLVMWebAssemblyCodeGen.a
libLLVMBOLTRuntimeLibs.a libLLVMMC.a libLLVMWebAssemblyDesc.a
libLLVMBOLTTargetAArch64.a libLLVMMCA.a libLLVMWebAssemblyDisassembler.a
libLLVMBOLTTargetX86.a libLLVMMCDisassembler.a libLLVMWebAssemblyInfo.a
libLLVMBOLTUtils.a libLLVMMCJIT.a libLLVMWebAssemblyUtils.a
libLLVMBPFAsmParser.a libLLVMMCParser.a libLLVMWindowsDriver.a
libLLVMBPFCodeGen.a libLLVMMIRParser.a libLLVMWindowsManifest.a
libLLVMBPFDesc.a libLLVMMSP430AsmParser.a libLLVMX86AsmParser.a
libLLVMBPFDisassembler.a libLLVMMSP430CodeGen.a libLLVMX86CodeGen.a
libLLVMBPFInfo.a libLLVMMSP430Desc.a libLLVMX86Desc.a
libLLVMBinaryFormat.a libLLVMMSP430Disassembler.a libLLVMX86Disassembler.a
libLLVMBitReader.a libLLVMMSP430Info.a libLLVMX86Info.a
libLLVMBitWriter.a libLLVMMipsAsmParser.a libLLVMX86TargetMCA.a
libLLVMBitstreamReader.a libLLVMMipsCodeGen.a libLLVMXCoreCodeGen.a
libLLVMCFGuard.a libLLVMMipsDesc.a libLLVMXCoreDesc.a
libLLVMCFIVerify.a libLLVMMipsDisassembler.a libLLVMXCoreDisassembler.a
libLLVMCodeGen.a libLLVMMipsInfo.a libLLVMXCoreInfo.a
libLLVMCore.a libLLVMNVPTXCodeGen.a libLLVMXRay.a
libLLVMCoroutines.a libLLVMNVPTXDesc.a libLLVMipo.a
libLLVMCoverage.a libLLVMNVPTXInfo.a libLTO.so
libLLVMDWARFLinker.a libLLVMObjCARCOpts.a libLTO.so.16
libLLVMDWP.a libLLVMObjCopy.a libPolly.a
libLLVMDebugInfoCodeView.a libLLVMObject.a libPollyISL.a
libLLVMDebugInfoDWARF.a libLLVMObjectYAML.a libRemarks.so
libLLVMDebugInfoGSYM.a libLLVMOption.a libRemarks.so.16
libLLVMDebugInfoLogicalView.a libLLVMOrcJIT.a libclang-16.so.1
libLLVMDebugInfoMSF.a libLLVMOrcShared.a libclang-cpp.so.16
libLLVMDebugInfoPDB.a libLLVMOrcTargetProcess.a libclang.so.1
libLLVMDebuginfod.a libLLVMPasses.a liblldb.so.1
libLLVMDemangle.a libLLVMPerfJITEvents.a liblldbIntelFeatures.so.16
libLLVMDiff.a libLLVMPowerPCAsmParser.a
Get various configuration information needed to compile programs which use
LLVM. Typically called from 'configure' scripts. Examples:
llvm-config --cxxflags
llvm-config --ldflags
llvm-config --libs engine bcreader scalaropts
Options:
--assertion-mode Print assertion mode of LLVM tree (ON or OFF).
--bindir Directory containing LLVM executables.
--build-mode Print build mode of LLVM tree (e.g. Debug or Release).
--build-system Print the build system used to build LLVM (e.g. `cmake` or `gn`).
--cflags C compiler flags for files that include LLVM headers.
--cmakedir Directory containing LLVM CMake modules.
--components List of all possible components.
--cppflags C preprocessor flags for files that include LLVM headers.
--cxxflags C++ compiler flags for files that include LLVM headers.
--has-rtti Print whether or not LLVM was built with rtti (YES or NO).
--help Print a summary of llvm-config arguments.
--host-target Target triple used to configure LLVM.
--ignore-libllvm Ignore libLLVM and link component libraries instead.
--includedir Directory containing LLVM headers.
--ldflags Print Linker flags.
--libdir Directory containing LLVM libraries.
--libfiles Fully qualified library filenames for makefile depends.
--libnames Bare library names for in-tree builds.
--libs Libraries needed to link against LLVM components.
--link-shared Link the components as shared libraries.
--link-static Link the component libraries statically.
--obj-root Print the object root used to build LLVM.
--prefix Print the installation prefix.
--shared-mode Print how the provided components can be collectively linked (`shared` or `static`).
--system-libs System Libraries needed to link against LLVM components.
--targets-built List of all targets currently built.
--version Print LLVM version.
Typical components:
all All LLVM libraries (default).
engine Either a native JIT or a bitcode interpreter.
Ubuntu clang version 16.0.0 (++20230109052936+64f06dda87cf-1~exp1~20230109173029.503)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/lib/llvm-16/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name 3.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/mnt/z/c -resource-dir /usr/lib/llvm-16/lib/clang/16 -I /lib/llvm-16/include/ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdeprecated-macro -fdebug-compilation-dir=/mnt/z/c -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/3-9b8468.o -x c++ 3.cpp
clang -cc1 version 16.0.0 based upon LLVM 16.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/lib/llvm-16/include
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward
/usr/lib/llvm-16/lib/clang/16/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
"/usr/bin/ld" -pie -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o 82-14 /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/3-9b8468.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtendS.o /lib/x86_64-linux-gnu/crtn.o
/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x25
/tmp/3-9b8468.o: in function `main':
3.cpp:(.text+0x26f): undefined reference to `llvm::LLVMContext::LLVMContext()'
/usr/bin/ld: 3.cpp:(.text+0x28a): undefined reference to `llvm::LLVMContext::~LLVMContext()'
/usr/bin/ld: 3.cpp:(.text+0x2c0): undefined reference to `llvm::Module::Module(llvm::StringRef, llvm::LLVMContext&)'/usr/bin/ld: 3.cpp:(.text+0x2db): undefined reference to `llvm::Module::~Module()'
/usr/bin/ld: 3.cpp:(.text+0x34b): undefined reference to `vtable for llvm::ConstantFolder'
/usr/bin/ld: 3.cpp:(.text+0x35a): undefined reference to `vtable for llvm::IRBuilderDefaultInserter'
/usr/bin/ld: 3.cpp:(.text+0x384): undefined reference to `llvm::IRBuilderDefaultInserter::~IRBuilderDefaultInserter()'
/usr/bin/ld: 3.cpp:(.text+0x38d): undefined reference to `llvm::IRBuilderFolder::~IRBuilderFolder()'
/usr/bin/ld: 3.cpp:(.text+0x5b7): undefined reference to `llvm::errs()'
/usr/bin/ld: 3.cpp:(.text+0x5c9): undefined reference to `llvm::Function::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*, bool, bool) const'
/usr/bin/ld: 3.cpp:(.text+0x5df): undefined reference to `llvm::Function::eraseFromParent()'
/usr/bin/ld: 3.cpp:(.text+0x61d): undefined reference to `llvm::errs()'
/usr/bin/ld: 3.cpp:(.text+0x62f): undefined reference to `llvm::Function::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*, bool, bool) const'
/usr/bin/ld: 3.cpp:(.text+0x705): undefined reference to `llvm::errs()'
/usr/bin/ld: 3.cpp:(.text+0x717): undefined reference to `llvm::Function::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*, bool, bool) const'
/usr/bin/ld: 3.cpp:(.text+0x760): undefined reference to `llvm::errs()'
/usr/bin/ld: 3.cpp:(.text+0x772): undefined reference to `llvm::Module::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*, bool, bool) const'
/usr/bin/ld: /tmp/3-9b8468.o: in function `(anonymous namespace)::FunctionAST::codegen()':
3.cpp:(.text+0xb94): undefined reference to `llvm::Module::getFunction(llvm::StringRef) const'
/usr/bin/ld: 3.cpp:(.text+0xbee): undefined reference to `llvm::BasicBlock::BasicBlock(llvm::LLVMContext&, llvm::Twine const&, llvm::Function*, llvm::BasicBlock*)'
/usr/bin/ld: 3.cpp:(.text+0xc5e): undefined reference to `llvm::Function::BuildLazyArguments() const'
/usr/bin/ld: 3.cpp:(.text+0xc78): undefined reference to `llvm::Function::BuildLazyArguments() const'
/usr/bin/ld: 3.cpp:(.text+0xcc1): undefined reference to `llvm::Value::getName() const'
/usr/bin/ld: 3.cpp:(.text+0xd89): undefined reference to `llvm::verifyFunction(llvm::Function const&, llvm::raw_ostream*)'
/usr/bin/ld: 3.cpp:(.text+0xd95): undefined reference to `llvm::Function::eraseFromParent()'
/usr/bin/ld: /tmp/3-9b8468.o: in function `(anonymous namespace)::CallExprAST::codegen()':
3.cpp:(.text+0x1e41): undefined reference to `llvm::Module::getFunction(llvm::StringRef) const'
/usr/bin/ld: /tmp/3-9b8468.o: in function `(anonymous namespace)::NumberExprAST::codegen()':
3.cpp:(.text+0x2153): undefined reference to `llvm::detail::IEEEFloat::IEEEFloat(double)'
/usr/bin/ld: 3.cpp:(.text+0x2158): undefined reference to `llvm::APFloatBase::IEEEdouble()'
/usr/bin/ld: 3.cpp:(.text+0x2166): undefined reference to `llvm::APFloat::Storage::Storage(llvm::detail::IEEEFloat, llvm::fltSemantics const&)'
/usr/bin/ld: 3.cpp:(.text+0x2170): undefined reference to `llvm::detail::IEEEFloat::~IEEEFloat()'
/usr/bin/ld: 3.cpp:(.text+0x217d): undefined reference to `llvm::ConstantFP::get(llvm::LLVMContext&, llvm::APFloat const&)'
/usr/bin/ld: 3.cpp:(.text+0x218a): undefined reference to `llvm::APFloatBase::PPCDoubleDouble()'
/usr/bin/ld: 3.cpp:(.text+0x2197): undefined reference to `llvm::detail::IEEEFloat::~IEEEFloat()'
/usr/bin/ld: 3.cpp:(.text+0x21dc): undefined reference to `llvm::detail::IEEEFloat::~IEEEFloat()'
/usr/bin/ld: /tmp/3-9b8468.o: in function `(anonymous namespace)::BinaryExprAST::codegen()':
3.cpp:(.text+0x2393): undefined reference to `llvm::IRBuilderBase::CreateFCmpHelper(llvm::CmpInst::Predicate, llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::MDNode*, bool)'
/usr/bin/ld: 3.cpp:(.text+0x23ad): undefined reference to `llvm::Type::getDoubleTy(llvm::LLVMContext&)'
/usr/bin/ld: 3.cpp:(.text+0x23ec): undefined reference to `llvm::IRBuilderBase::CreateConstrainedFPCast(unsigned int, llvm::Value*, llvm::Type*, llvm::Instruction*, llvm::Twine const&, llvm::MDNode*, std::optional<llvm::RoundingMode>, std::optional<llvm::fp::ExceptionBehavior>)'
/usr/bin/ld: /tmp/3-9b8468.o: in function `(anonymous namespace)::PrototypeAST::codegen()':
3.cpp:(.text+0x2467): undefined reference to `llvm::Type::getDoubleTy(llvm::LLVMContext&)'
/usr/bin/ld: 3.cpp:(.text+0x2504): undefined reference to `llvm::Type::getDoubleTy(llvm::LLVMContext&)'
/usr/bin/ld: 3.cpp:(.text+0x251b): undefined reference to `llvm::FunctionType::get(llvm::Type*, llvm::ArrayRef<llvm::Type*>, bool)'
/usr/bin/ld: 3.cpp:(.text+0x253b): undefined reference to `llvm::User::operator new(unsigned long)'
/usr/bin/ld: 3.cpp:(.text+0x2558): undefined reference to `llvm::Function::Function(llvm::FunctionType*, llvm::GlobalValue::LinkageTypes, unsigned int, llvm::Twine const&, llvm::Module*)'
/usr/bin/ld: 3.cpp:(.text+0x2570): undefined reference to `llvm::Function::BuildLazyArguments() const'
/usr/bin/ld: 3.cpp:(.text+0x2588): undefined reference to `llvm::Function::BuildLazyArguments() const'
/usr/bin/ld: 3.cpp:(.text+0x25ce): undefined reference to `llvm::Value::setName(llvm::Twine const&)'
/usr/bin/ld: 3.cpp:(.text+0x2614): undefined reference to `llvm::User::operator delete(void*)'
/usr/bin/ld: /tmp/3-9b8468.o: in function `std::unique_ptr<llvm::LLVMContext, std::default_delete<llvm::LLVMContext> >::~unique_ptr()':
3.cpp:(.text._ZNSt10unique_ptrIN4llvm11LLVMContextESt14default_deleteIS1_EED2Ev[_ZNSt10unique_ptrIN4llvm11LLVMContextESt14default_deleteIS1_EED2Ev]+0x13): undefined reference to `llvm::LLVMContext::~LLVMContext()'
/usr/bin/ld: /tmp/3-9b8468.o: in function `std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >::~unique_ptr()':
3.cpp:(.text._ZNSt10unique_ptrIN4llvm6ModuleESt14default_deleteIS1_EED2Ev[_ZNSt10unique_ptrIN4llvm6ModuleESt14default_deleteIS1_EED2Ev]+0x13): undefined reference to `llvm::Module::~Module()'
/usr/bin/ld: /tmp/3-9b8468.o: in function `std::unique_ptr<llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>, std::default_delete<llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter> > >::~unique_ptr()':
(...) etc.
/usr/bin/ld: 3.cpp:(.text._ZN4llvm13IRBuilderBase9CreateRetEPNS_5ValueE[_ZN4llvm13IRBuilderBase9CreateRetEPNS_5ValueE]+0x7b): undefined reference to `llvm::Instruction::setMetadata(unsigned int, llvm::MDNode*)'
/usr/bin/ld: 3.cpp:(.text._ZN4llvm13IRBuilderBase9CreateRetEPNS_5ValueE[_ZN4llvm13IRBuilderBase9CreateRetEPNS_5ValueE]+0x9e): undefined reference to `llvm::User::operator delete(void*)'
/usr/bin/ld: /tmp/3-9b8468.o:(.data+0x0): undefined reference to `llvm::DisableABIBreakingChecks'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any ideas? Thanks.
The solution was to start a fresh WSL instance... :) In the new one it started compiling.
One more note, for the parts of the tutorial having an "extern printd()" such as part 6 etc., if using clang++ as suggested, add "-Wl,--export-dynamic" to the clang++ part of the command line, otherwise the extern printd() function couldn't be resolved.
A specific call for my case (however I don't use the folder structure from the example which is ../include/KaleidoscopeJIT.h from the repository, I copied only this file to the current directory):
clang++ -g 6.cpp -I KaleidoscopeJIT.h -Wl,--export-dynamic $(llvm-co
nfig --cxxflags --ldflags --system-libs --libs core orcjit native ) -O3 -o 62
./62
ready> extern printd(x);
ready> Read extern: declare double #printd(double)
ready> printd(1)
ready> ;
1.000000
Evaluated to 0.000000
The following snippet:
#include <string>
#include <iostream>
int main()
{
std::string s = std::to_string(5);
std::cout << s << std::endl;
return 0;
}
Fails to link with Clang 3.6 on windows (accompanied with gcc 4.8.2 headers and libraries) when given the following options:
clang++ -std=c++11 -static -O0 bug.cpp
Please note that with -O2 the snippet compiles and links fine, so i suspect it may be some kind of clang bug.
EDIT 1:
I forgot to put the link error:
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2\libstdc++.a(string-inst.o):(.text$_ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): multiple definition of
`char* std::string::_S_construct<char*>(char*, char*, std::allocator<char> const&, std::forward_iterator_tag)'
C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o:(.text[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): first defined here
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2\libstdc++.a(string-inst.o):(.text$_ZNSsC2IPcEET_S1_RKSaIcE[__ZNSsC2IPcEET_S1_RKSaIcE]+0x0): multiple definition of `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<char*>(char*, char*, std::allocator<char> const&)'
C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o:(.text[__ZNSsC2IPcEET_S1_RKSaIcE]+0x0): first defined here
F:/Programs/LLVM/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: C:\Users\THEART~1\AppData\Local\Temp\bug-b5df09.o: bad reloc address 0x10 in section `.text[__ZSt9to_stringi]'
collect2.exe: error: ld returned 1 exit status
clang++.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
EDIT 2:
I've been asked why i added the static flag in the compilation flags.
My purpose was to generate full static linked executables without the need of some gcc dlls (libstdc++6.dll libwinpthread.dll etc) so i have mostly been compiling with this command:
clang++ -std=c++11 -static -static-libstdc++ -static-libgcc -O0 bug.cpp
that i've been using with gcc too to generate full static executables.
After some experimenting i noticed that the combination of -static and -O0 flags is the problematic one so i omitted the others to not create any confusion.
I'm new to opencv in ubuntu. I've follow the tutorial from here for setting up the opencv in linux. However, I have failed to make the sample program runs. After I type the following,
$ g++ DisplayImage.cpp
These error appears,
/tmp/cc3GTOtQ.o: In function `main':
DisplayImage.cpp:(.text+0x53): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0xe5): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
DisplayImage.cpp:(.text+0x113): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
DisplayImage.cpp:(.text+0x147): undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
DisplayImage.cpp:(.text+0x169): undefined reference to `cv::waitKey(int)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::~Mat()':
DisplayImage.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::operator=(cv::Mat const&)':
DisplayImage.cpp:(.text._ZN2cv3MataSERKS0_[cv::Mat::operator=(cv::Mat const&)]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/cc3GTOtQ.o: In function `cv::Mat::release()':
DisplayImage.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x47): undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
Here is the full command line build C++ program with OpenCV Libraries.
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binaryName main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy
If you installed OpenCV in different location, you should change the path of 'include' and lib 'directory' to appropriate location.
Edit:-
Instead of running this command every time just create a file build.sh in your project directory, change it's permission to executable by running chmod 777 build.sh and for building the project just run this file.
You need to link with the opencv libraries: probably you'll need to add at least -lcv and maybe -lcxcore and -lhighgui to your command line. See this similar question.
I am trying to compile a project and you can find the makefile at this link here https://dl.dropbox.com/u/95042389/Makefile
I have installed ANN and OpenCV 2.3.1.
When I type make, it is returning the errors given below.
sai#sai-HP-EliteBook-8460w:~/workspace/4pcs$ make
g++ -L/home/sai/workspace/OpenCV-2.4.1/lib -L/home/sai/workspace/ann_1.1.2/lib -L/usr/lib 4pcs.o 4pcs_test.o -o 4pcs -lopencv_highgui -lANN -o 4pcs
/usr/bin/ld: 4pcs.o: undefined reference to symbol 'cv::operator*(cv::Mat const&, cv::Mat const&)'
/usr/bin/ld: note: 'cv::operator*(cv::Mat const&, cv::Mat const&)' is defined in DSO /usr/lib/libopencv_core.so.2.3 so try adding it to the linker command line
/usr/lib/libopencv_core.so.2.3: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make: * [4pcs] Error 1
Then I tried this
sai#sai-HP-EliteBook-8460w:~/workspace/4pcs$ echo $LD_LIBRARY_PATH
/usr/lib:/opt/ros/fuerte/lib:/opt/ros/fuerte/lib:/usr/lib/libopencv_core.2.3
Still the same errors..
Any suggestions?
It was solved by adding
-lopencv_core and then it worked with no errors.
I am trying to cross compile a sample OpenCV cpp code for my beaglebone which has a ARM Cortex A8 based AM3359 processor. However when I start the cross-compiling I get the following error:
/usr/local/lib/libopencv_calib3d.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
It seems like a linker error. I am pretty sure that there is nothing wrong with libopencv_calib3d.so. Because when I compile the program for my PC, everything works fine. Therefore maybe the problem is with the method that I am using for cross compiling. Here is what I do:
I wrote a script in the name of compile_opencvarm.sh:
echo "Cross-Compiling $1"
if [[ $1 == *.c ]]
then
arm-linux-gnueabi-gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`;
elif [[ $1 == *.cpp ]]
then
arm-linux-gnueabi-g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;
else
echo "Please compile only .c or .cpp files with this script"
fi
echo "Cross-Compiled Output => ${1%.*}"
and then added it to bashrc:
alias opencv_arm="~/.compile_opencvarm.sh"
Now when I do:
root#ghostrider:/home/zero/Desktop# opencv_arm peopledetect.cpp
Cross-Compiling peopledetect.cpp
/usr/local/lib/libopencv_calib3d.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
Cross-Compiled Output => peopledetect
Only difference with compiling script and cross-compiling script is that I used arm-linux-gnueabi prefix in the cross-compiling script. When I only compile the cpp file:
root#ghostrider:/home/zero/Desktop# opencv peopledetect.cpp
compiling peopledetect.cpp
Output file => peopledetect
Everything is OK. Program is executable.
Now what do you think my problem is? Is it a linker error or is it related to my cross-compiling process?
Regards
edit: Oh, now I noticed that I did not install arm-based cross libraries before the arm-linux-gnueabi compiler used them. So I installed them with:
sudo xapt -a armel -m libv4l-dev libgtk2.0-dev libcv-dev libcvaux-dev libhighgui-dev
and edited the script as following:
arm-linux-gnueabi-g++ -ggdb `arm-linux-gnueabi-pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `arm-linux-gnueabi-pkg-config --libs opencv`;
But now I get the problem:
root#ghostrider:/home/zero/Desktop# opencv_arm peopledetect.cpp
compiling peopledetect.cpp
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: liblapack.so.3gf, needed by /usr/arm-linux-gnueabi/lib/libcxcore.so, not found (try using -rpath or -rpath-link)
/tmp/ccDzUCLJ.o: In function `main':
/home/zero/Desktop/peopledetect.cpp:49: undefined reference to `cv::HOGDescriptor::setSVMDetector(cv::_InputArray const&)'
/home/zero/Desktop/peopledetect.cpp:84: undefined reference to `cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const'
/tmp/ccDzUCLJ.o: In function `cv::Mat::operator=(cv::Mat const&)':
/usr/include/opencv2/core/mat.hpp:317: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccDzUCLJ.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.hpp:382: undefined reference to `cv::Mat::deallocate()'
/tmp/ccDzUCLJ.o: In function `_InputArray<float>':
/usr/include/opencv2/core/mat.hpp:1108: undefined reference to `vtable for cv::_InputArray'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgelsd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dsyevr_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgesv_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotrs_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgetri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgels_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgesv_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgetrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgetrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgels_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgelsd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgesdd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `ssyevr_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgesdd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotrs_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgetri_'
collect2: ld returned 1 exit status
Output file => peopledetect
I solved my problem by cross-compiling all the OpenCV libraries by following this guide: http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8
I followed this guide but "lnclude/opencv2" directory in the root of opencv distributive is empty after the building. So in fact i have libraries but dont have headers. What am i doing wrong?
UPD: I should be a little more careful, all answers in http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8