Build WebRTC with OpenCV - opencv

I am trying to build WebRTC with OpenCV. I built OpenCV with cmake and make installed it. In PeerConnection example i included opencv libs and headers. when i call ninja build i get the following error:
ninja -C out/Default
ninja: Entering directory `out/Default'
[1/16] LINK ./peerconnection_client
FAILED: peerconnection_client
../../third_party/llvm-build/Release+Asserts/bin/clang++ -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core -ldl -lm -lpthread -lrt -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--no-as-needed -lpthread -Wl,--as-needed -fuse-ld=gold -B../../third_party/binutils/Linux_x64/Release/bin -Wl,--threads -Wl,--thread-count=4 -Wl,--icf=all -m64 -pthread -Werror --sysroot=../../build/linux/debian_wheezy_amd64-sysroot -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu/4.6 -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib -Wl,-rpath-link=/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib -Wl,-rpath-link=. -Wl,--disable-new-dtags -Wl,-rpath=\$ORIGIN/. -Wl,-rpath-link=. -Wl,--export-dynamic -o "./peerconnection_client" -Wl,--start-group #"./peerconnection_client.rsp" ./libboringssl.so ./libprotobuf_lite.so -Wl,--end-group -lX11 -lXcomposite -lXext -lXrender -ldl -lrt -lgmodule-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lfreetype -lfontconfig -lgthread-2.0 -lglib-2.0 -lexpat -lm
/usr/local/lib/libopencv_objdetect.so: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)', version 'GLIBCXX_3.4.20'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_shape.so: error: undefined reference to 'memcpy', version 'GLIBC_2.14'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_stitching.so: error: undefined reference to 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream(std::_Ios_Openmode)', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()', version 'GLIBCXX_3.4.21'
/usr/local/lib/libopencv_flann.so: error: undefined reference to 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)', version 'GLIBCXX_3.4.21'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
My gcc version is 5.4.0.
Result of locate libstdc++.so.6 :
/home/parallels/webrt_blog/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrt_blog/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrt_blog/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrt_blog/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
/home/parallels/webrt_blog/src/third_party/llvm-build/Release+Asserts/lib/libstdc++.so.6
/home/parallels/webrtc/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrtc/rootfs/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_arm-sysroot/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/debian_wheezy_i386-sysroot/usr/lib/i386-linux-gnu/libstdc++.so.6.0.17
/home/parallels/webrtc/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/home/parallels/webrtc/src/build/linux/ubuntu_precise_amd64-sysroot/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
/home/parallels/webrtc/src/third_party/llvm-build/Release+Asserts/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17
/opt/rpi_tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17-gdb.py
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17
/opt/rpi_tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot/lib/libstdc++.so.6.0.17-gdb.py
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6.0.20
/opt/rpi_tools/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/arm-linux-gnueabihf/sysroot/lib/libstdc++.so.6.0.20-gdb.py
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19-gdb.py
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19
/opt/rpi_tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf/lib/libstdc++.so.6.0.19-gdb.py
/usr/lib/parallels-tools/installer/iagent32/libs/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent32/libs/libstdc++.so.6/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent64/libs/libstdc++.so.6
/usr/lib/parallels-tools/installer/iagent64/libs/libstdc++.so.6/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21-gdb.py
I guess cmake opencv uses /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
and webrtc ninja seems to use libstdc++.so.6.0.16. This may cause a conflict.Is the reason of the error this conflict? If yes how can i resolve it?

This problem is about the incompatible version of libc and libstdc++ libraries between WebRTC and the libraries in the system.
Solution is to copy two files and rebuild the soft links
First, copy /usr/lib/x86_64-linux-gnu/libstdc++.so.6.xx to this path /WebRTC/Path/src/build/linux/debian_wheezy_amd64-sysroot/usr/lib/x86_64-linux-gnu and rebuild the libstdc++.so.6 link to point to the new copied library
Secondly, copy /lib/x86_64-linux-gnu/libc-xx.so to /WebRTC/Path//home/faraklit/projects/webrtc-checkout/src/build/linux/debian_wheezy_amd64-sysroot/lib/x86_64-linux-gnu
and rebuild the libc.so.6 link to point to the new copied library

Related

Linking LLVM-16 with Clang++ 16 when Compiling the Kaleidoscope examples with C++14 on Ubuntu 20.04 WSL2 Windows 10

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

Darknet make error: lot of undefined reference error with OpenCV library

I'm trying to make the darknet (My Makefile) on a computing cluster, with module devel/cuda/10.2 and module devel/cudnn/10.2 loaded.
Cuda Path: /opt/bwhpc/common/devel/cuda/10.2/
CuDNN path: /opt/bwhpc/common/devel/cudnn/10.2/
OpenCV path: /home/kit/fast/zx7186/.conda/envs/yoloenv/lib/ (conda environment)
It occured a lot of undefined reference make error(full version):
part of them like following:
g++ -std=c++11 -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv` -DGPU -I/opt/bwhpc/common/devel/cuda/10.2/include/ -DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -I/opt/bwhpc/common/devel/cudnn/10.2/include obj/image_opencv.o obj/http_stream.o obj/gemm.o obj/utils.o obj/dark_cuda.o obj/convolutional_layer.o obj/list.o obj/image.o obj/activations.o obj/im2col.o obj/col2im.o obj/blas.o obj/crop_layer.o obj/dropout_layer.o obj/maxpool_layer.o obj/softmax_layer.o obj/data.o obj/matrix.o obj/network.o obj/connected_layer.o obj/cost_layer.o obj/parser.o obj/option_list.o obj/darknet.o obj/detection_layer.o obj/captcha.o obj/route_layer.o obj/writing.o obj/box.o obj/nightmare.o obj/normalization_layer.o obj/avgpool_layer.o obj/coco.o obj/dice.o obj/yolo.o obj/detector.o obj/layer.o obj/compare.o obj/classifier.o obj/local_layer.o obj/swag.o obj/shortcut_layer.o obj/activation_layer.o obj/rnn_layer.o obj/gru_layer.o obj/rnn.o obj/rnn_vid.o obj/crnn_layer.o obj/demo.o obj/tag.o obj/cifar.o obj/go.o obj/batchnorm_layer.o obj/art.o obj/region_layer.o obj/reorg_layer.o obj/reorg_old_layer.o obj/super.o obj/voxel.o obj/tree.o obj/yolo_layer.o obj/gaussian_yolo_layer.o obj/upsample_layer.o obj/lstm_layer.o obj/conv_lstm_layer.o obj/scale_channels_layer.o obj/sam_layer.o obj/convolutional_kernels.o obj/activation_kernels.o obj/im2col_kernels.o obj/col2im_kernels.o obj/blas_kernels.o obj/crop_layer_kernels.o obj/dropout_layer_kernels.o obj/maxpool_layer_kernels.o obj/network_kernels.o obj/avgpool_layer_kernels.o -o darknet -lm -pthread `pkg-config --libs opencv4 2> /dev/null || pkg-config --libs opencv` -L/opt/bwhpc/common/devel/cuda/10.2/lib64 -lcudart -lcublas -lcurand -L/opt/bwhpc/common/devel/cuda/10.2/lib64/stubs -lcuda -L/opt/bwhpc/common/devel/cudnn/10.2/lib64 -lcudnn -lstdc++
/usr/bin/ld: warning: libhdf5.so.101, needed by /home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_hdf.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libpng16.so.16, needed by /home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libjasper.so.4, needed by /home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `av_dict_set#LIBAVUTIL_56'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so: undefined reference to `png_create_read_struct#PNG16_0'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_hdf.so: undefined reference to `H5Dread'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so: undefined reference to `png_set_interlace_handling#PNG16_0'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_hdf.so: undefined reference to `H5Tarray_create2'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `av_packet_unref#LIBAVCODEC_58'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so: undefined reference to `png_error#PNG16_0'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_hdf.so: undefined reference to `H5Tset_size'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `av_read_frame#LIBAVFORMAT_58'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_stdio_dest#LIBJPEG_9.0'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `avformat_find_stream_info#LIBAVFORMAT_58'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_hdf.so: undefined reference to `H5P_CLS_DATASET_CREATE_ID_g'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `avcodec_find_decoder#LIBAVCODEC_58'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_imgcodecs.so: undefined reference to `png_set_strip_16#PNG16_0'
/home/kit/fast/zx7186/.conda/envs/yoloenv/lib/libopencv_videoio.so: undefined reference to `avformat_write_header#LIBAVFORMAT_58'
collect2: error: ld returned 1 exit status
make: *** [darknet] Error 1
Is this the problem of OpenCV? How could I fix it?
Thank you for your help.

How to configure the linking g++ with opecv properly in ubuntu 18.04?

I'm new to opencv. And I'm found out that the pkg-config --cflags --libs opencv -lopencv_core -lopencv_imgcodecs should be used to make compile smoothly. But I just don't know why keeping get the "undefined reference" error when compiling, the output results and my Makefile are as follows:
1. For outputs:
g++ -Wall -g opencv.cpp
/tmp/ccg5WiIh.o: In function `main':
/home/akatsuki/Documents/Projects/simpleTest/opencv/opencv.cpp:14: undefined reference to `cv::imread(cv::String const&, int)'
/home/akatsuki/Documents/Projects/simpleTest/opencv/opencv.cpp:25: undefined reference to `cv::namedWindow(cv::String const&, int)'
/home/akatsuki/Documents/Projects/simpleTest/opencv/opencv.cpp:26: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/akatsuki/Documents/Projects/simpleTest/opencv/opencv.cpp:29: undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
/home/akatsuki/Documents/Projects/simpleTest/opencv/opencv.cpp:31: undefined reference to `cv::waitKey(int)'
/tmp/ccg5WiIh.o: In function `cv::String::String(char const*)':
/usr/include/opencv2/core/cvstd.hpp:622: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccg5WiIh.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:664: undefined reference to `cv::String::deallocate()'
/tmp/ccg5WiIh.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:592: undefined reference to `cv::fastFree(void*)'
/tmp/ccg5WiIh.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:704: undefined reference to `cv::Mat::deallocate()'
/tmp/ccg5WiIh.o: In function `cv::Mat::operator=(cv::Mat&&)':
/usr/include/opencv2/core/mat.inl.hpp:1215: undefined reference to `cv::fastFree(void*)'
collect2: error: ld returned 1 exit status
Makefile:16: recipe for target 'opencv.o' failed
make: *** [opencv.o] Error 1
2. For Makefile:
CC = g++
CCFLAG = -Wall -g
Linker = `pkg-config --cflags --libs opencv` -lopencv_core -lopencv_imgcodecs
all: opencv.exe
opencv.exe: opencv.o
g++ -o $# opencv.o $(Linker)
chmod a+x $#
opencv.o: opencv.cpp
$(CC) $(CCFLAG) opencv.cpp
Could anyone help me figure out the problem? Thanks~
For anyone who searches relevant issues, I leave reply.
Following command prints directories of OpenCV header files.
pkg-config --cflags opencv
// -I/usr/local/include/opencv -I/usr/local/include
Following command prints shared object files
(under /usr/local/lib directory in following case)
which are used for dynamic linking.
Dynamic linking is to link your excutable file (like main file)
to shared object files (like .so files) at runtime
pkg-config --libs opencv
// -L/usr/local/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect
// -lopencv_cudastereo -lopencv_stitching -lopencv_cudafeatures2d
// -lopencv_superres -lopencv_cudacodec -lopencv_videostab
// ...
You can use above printed dependencies
(header file directories and shared object files) in your compilation command
by writing pkg-config --cflags opencv and pkg-config --libs opencv
g++ `pkg-config --cflags opencv` \
-o main \
/your_cpp_file_path/source.cpp \
`pkg-config --libs opencv`
Note that ` is backtick character, not '
backtick character in linux command is used
to use a result from command in command
For example, this part pkg-config --cflags opencv is replaced
with the result from pkg-config --cflags opencv

Can't link libFuzzer.a using clang with libc++

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 )

Sample Program From Terminal Could Not Run

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.

Resources