While building the protobuf and protobuf-c and clang. I'm facing some error. What my guess is I'm unable to link the protobuf while invoking the cmake for building clang despite me passing -L/usr/local/lib this flag. And my protobuf is installed in /usr/local/lib.
I'm using Ubuntu 22.04.2 LTS
.
G++ version: g++ (Ubuntu 8.4.0-3ubuntu2) 8.4.0
The code for protobuf and protobuf-c build:
echo
echo -e "${BLUE}===================== build protobuf ======================${NC}"
echo
if [ -f ${PWD_PATH}/succeed/protobuf ]; then
cd $PWD_PATH
# eval "git clone https://github.com/protocolbuffers/protobuf.git"
eval "cd protobuf && git checkout v3.15.8 && git submodule update --init --recursive && ./autogen.sh"
eval "./configure && make -j$(nproc) && sudo make install && sudo ldconfig"
echo "done" > ${PWD_PATH}/succeed/protobuf
fi
echo
echo -e "${GREEN}[*] build protobuf succeed!${NC}"
# build protobuf-c
echo
echo -e "${BLUE}===================== build protobuf-c =======================${NC}"
echo
cd $PWD_PATH
if [ -f ${PWD_PATH}/succeed/protobuf-c ]; then
echo "git clone https://github.com/protobuf-c/protobuf-c.git"
# eval "git clone https://github.com/protobuf-c/protobuf-c.git"
# export LD_RUN_PATH=/usr/local/lib
# export LD_LIBRARY_PATH=/usr/local/lib/
# export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
eval 'cd protobuf-c && git checkout v1.4.0 && ./autogen.sh && ./configure && make -j$(nproc) && sudo make install'
eval 'sudo ln -sf /usr/local/lib/libprotobuf-c.so.1.0.0 /usr/lib/libprotobuf-c.so.1'
echo "done" > ${PWD_PATH}/succeed/protobuf-c
fi
echo
echo -e "${GREEN}[*] build protobuf-c succeed!${NC}"
The code for building clang:
echo -e "${BLUE}======================= build clang ===============================${NC}"
echo
LLVM_PATH=${SRC_PATH}/llvm/llvm-6.0.0
BINUTILS_PATH=${PWD_PATH}/binutils-2.30
cd $PWD_PATH
if [ -f ${PWD_PATH}/succeed/clang ]; then
mkdir -p build_rust
LLVM_BUILD_DIR=${PWD_PATH}/build_rust
cd build_rust
cmake ${LLVM_PATH} -DCMAKE_EXE_LINKER_FLAGS_DEBUG="-I/usr/local/include -L/usr/local/lib -lprotobuf -lpthread" -DLLVM_ENABLE_RTTI=ON -DLLVM_BINUTILS_INCDIR=$BINUTILS_PATH/include -DCMAKE_BUILD_TYPE=Release
MODIFIED_LINK1="$LLVM_BUILD_DIR/lib/MC/CMakeFiles/LLVMMC.dir/link.txt"
MODIFIED_LINK2="$LLVM_BUILD_DIR/tools/lto/CMakeFiles/LTO.dir/link.txt"
MODIFIED_LINK3="$LLVM_BUILD_DIR/tools/clang/tools/libclang/CMakeFiles/libclang.dir/link.txt"
MODIFIED_LINK4="$LLVM_BUILD_DIR/tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/link.txt"
# Adding /usr/lib/shuffleInfo.so
sed -i '/LLVMMC.dir/s/$/\ \/usr\/lib\/shuffleInfo\.so/' $MODIFIED_LINK1
# Adding -I/usr/local/include -L/usr/local/lib -lprotobuf
sed -i 's/$/\-I\/usr\/local\/include\ \-L\/usr\/local\/lib\ \-lprotobuf/' $MODIFIED_LINK2
sed -i 's/$/\-I\/usr\/local\/include\ \-L\/usr\/local\/lib\ \-lprotobuf/' $MODIFIED_LINK3
sed -i 's/$/\-I\/usr\/local\/include\ \-L\/usr\/local\/lib\ \-lprotobuf/' $MODIFIED_LINK4
cp $PROTODEF_DIR/$CC_HDR $LLVM_PATH/include/llvm/Support/$CC_HDR
make -j$(nproc)
# make
echo "done" > ${PWD_PATH}/succeed/clang
fi
echo
echo -e "${GREEN}[*] build clang succeed!"
echo
The error:
../../lib/libLLVMMC.a(MCAssembler.cpp.o):MCAssembler.cpp:function serializeReorderInfo(ShuffleInfo::ReorderInfo*, llvm::MCAsmLayout const&): error: undefined reference to 'google::protobuf::internal::ArenaStringPtr::Set(google::protobuf::internal::ArenaStringPtr::EmptyDefault, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::Arena*)'
../../lib/libLLVMMC.a(MCAssembler.cpp.o):MCAssembler.cpp:function llvm::MCAssembler::WriteRandInfo(llvm::MCAsmLayout const&) const: error: undefined reference to 'google::protobuf::MessageLite::SerializeToString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
../../lib/libLLVMMC.a(MCAssembler.cpp.o):MCAssembler.cpp:function llvm::MCAssembler::WriteRandInfo(llvm::MCAsmLayout const&) const: error: undefined reference to 'google::protobuf::ShutdownProtobufLibrary()'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/dsymutil/CMakeFiles/llvm-dsymutil.dir/build.make:337: bin/llvm-dsymutil] Error 1
make[1]: *** [CMakeFiles/Makefile2:46774: tools/dsymutil/CMakeFiles/llvm-dsymutil.dir/all] Error 2
make: *** [Makefile:156: all] Error 2