树莓派编译FISCO-BCOS 2.10.0
树莓派启动ssh root用户:https://www.vlanl.com/archives/18/
FISCO BCOS 源码编译文档:https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/tutorial/compile.html
使用64位操作系统
操作系统需要是64位的。因为FISCO-BCOS does not support compiling on 32-bit systems。
具体原因是rocksdb不再支持32位操作系统,具体代码如下:
cpp
// Get the value of tokutime for right now. We want this to be fast, so we
// expose the implementation as RDTSC.
static inline tokutime_t toku_time_now(void) {
#if defined(__x86_64__) || defined(__i386__)
uint32_t lo, hi;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return (uint64_t)hi << 32 | lo;
#elif defined(__aarch64__)
uint64_t result;
__asm __volatile__("mrs %[rt], cntvct_el0" : [ rt ] "=r"(result));
return result;
#elif defined(__powerpc__)
return __ppc_get_timebase();
#elif defined(__s390x__)
uint64_t result;
asm volatile("stckf %0" : "=Q"(result) : : "cc");
return result;
#else
#error No timer implementation for this platform // 32位系统会在这里报错
#endif
}
FISCO BCOS使用的是rocksdb_6.29.3版本,而根据RocksDB 6.22.1 fails to build on ARM · Issue #8609 · facebook/rocksdb说提到的,rocksdb_6.15版本依然可以在arm32位系统上构建。
cmake版本高于3.20
编译需要cmake 3.20以上,所以需要手动编译安装cmake
bash
tar zxvf cmake-3.26.3.tar.gz
cd cmake-3.26.3
./configure
make -j $(nproc)
sudo make install
安装依赖包
bash
sudo apt install -y g++ libssl-dev openssl cmake git build-essential autoconf texinfo flex patch bison libgmp-dev zlib1g-dev automake libtool
上面命令是官方文档给出的依赖包,安装完这些包之后,还需要安装snappy库:
bash
sudo apt install libsnappy-dev
否则节点启动时无法连接到rocksdb。
编译
拉取代码:
bash
git clone https://github.com/FISCO-BCOS/FISCO-BCOS.git
cd FISCO-BCOS
git checkout release-2.10.0
编译:
bash
mkdir -p build && cd build
cmake -DARCH_NATIVE=on ..
make -j $(nproc)
编译配置
bash
root@raspberrypi:~/FISCO-BCOS/build# cmake -DARCH_NATIVE=on ..
------------------------------------------------------------------------
-- Configuring FISCO-BCOS 2.10.0
------------------------------------------------------------------------
-- CMake Cmake version and location 3.26.3 (/usr/local/bin/cmake)
-- Compiler C++ compiler version GNU 10.2.1
-- CMAKE_BUILD_TYPE Build type RelWithDebInfo
-- TARGET_PLATFORM Target platform Linux aarch64
-- BUILD_STATIC Build static OFF
-- USE_HSM_SDF Build SDF HSM OFF
-- DEMO Build demos OFF
-- TOOL Build tools OFF
-- COVERAGE Build code coverage OFF
-- TESTS Build tests OFF
-- APPLE Apple Machine
-- ARCH_NATIVE Enable native code ON
-- DEBUG Enable debug macro OFF
-- PROF Enable gcc prof OFF
-- WITH_URING Compile with liburing OFF
------------------------------------------------------------------------
编译
bash
root@raspberrypi:~/FISCO-BCOS/build# make -j $(nproc)
[ 0%] Built target BuildInfo.h
[ 2%] Built target tbb
[ 4%] Built target snappy
[ 6%] Built target leveldb
[ 8%] Built target rocksdb
[ 10%] Built target mhd
[ 12%] Built target cryptopp
[ 14%] Built target secp256k1
[ 16%] Built target jsoncpp
[ 18%] Built target jsonrpccpp
[ 20%] Built target tassl
[ 22%] Built target boost
[ 24%] Built target mysqlclient
[ 26%] Built target libzdb
[ 28%] Built target gperftools
[ 31%] Built target mpir
[ 33%] Built target libff
[ 35%] Built target paillier
[ 37%] Built target evmc
[ 39%] Built target libvrf
[ 42%] Built target evmone
[ 44%] Built target GroupSigLib
[ 49%] Built target devcore
[ 53%] Built target devcrypto
[ 57%] Built target ethcore
[ 58%] Built target eventfilter
[ 59%] Built target stat
[ 60%] Built target flowlimit
[ 62%] Built target txpool
[ 64%] Built target blockverifier
[ 65%] Built target executivecontext
[ 73%] Built target precompiled
[ 78%] Built target storage
[ 80%] Built target network
[ 81%] Built target p2p
[ 82%] Built target security
[ 84%] Built target mptstate
[ 85%] Built target storagestate
[ 85%] Built target blockchain
[ 88%] Built target sync
[ 92%] Built target consensus
[ 94%] Built target ledger
[ 94%] Building CXX object libinitializer/CMakeFiles/initializer.dir/GlobalConfigureInitializer.cpp.o
[ 94%] Linking CXX static library libinitializer.a
[ 96%] Built target initializer
[ 98%] Built target rpc
[ 99%] Built target channelserver
[ 99%] Building CXX object fisco-bcos/main/CMakeFiles/fisco-bcos.dir/main.cpp.o
[100%] Linking CXX executable ../../bin/fisco-bcos
[100%] Built target fisco-bcos
root@raspberrypi:~/FISCO-BCOS/build# exit
错误处理
rocksdb找不到函数
如果编译到最后时链接报错:
bash
[100%] Linking CXX executable ../../bin/fisco-bcos
/usr/bin/ld: /root/FISCO-BCOS/deps/src/rocksdb/librocksdb.a(crc32c.cc.o): in function `rocksdb::crc32c::ExtendARMImpl(unsigned int, char const*, unsigned long)':
crc32c.cc:(.text+0x0): undefined reference to `crc32c_arm64(unsigned int, unsigned char const*, unsigned long)'
/usr/bin/ld: /root/FISCO-BCOS/deps/src/rocksdb/librocksdb.a(crc32c.cc.o): in function `rocksdb::crc32c::IsFastCrc32Supported[abi:cxx11]()':
crc32c.cc:(.text+0x250): undefined reference to `crc32c_runtime_check()'
/usr/bin/ld: crc32c.cc:(.text+0x274): undefined reference to `crc32c_pmull_runtime_check()'
/usr/bin/ld: /root/FISCO-BCOS/deps/src/rocksdb/librocksdb.a(crc32c.cc.o): in function `_GLOBAL__sub_I_crc32c.cc':
crc32c.cc:(.text.startup+0x8): undefined reference to `crc32c_runtime_check()'
/usr/bin/ld: crc32c.cc:(.text.startup+0x2c): undefined reference to `crc32c_pmull_runtime_check()'
collect2: error: ld returned 1 exit status
make[2]: *** [fisco-bcos/main/CMakeFiles/fisco-bcos.dir/build.make:163: bin/fisco-bcos] Error 1
make[1]: *** [CMakeFiles/Makefile2:2088: fisco-bcos/main/CMakeFiles/fisco-bcos.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
解决方法:https://github.com/FISCO-BCOS/FISCO-BCOS/issues/2517#issuecomment-1505735092
rocksdb启动失败
如果启动bcos失败,日志报错如下:
bash
Dynamic exception type: boost::exception_detail::clone_impl<dev::DatabaseNeedRetry>
std::exception::what: std::exception
[dev::tag_comment*] = access rocksDB failed, status: Invalid argument: Compression type Snappy is not linked with the binary., path:/root/node0/data/group1/block/RocksDB, please try again!
info|2023-04-13 10:05:27.729819|[DBINITIALIZER] storage stopped
error|2023-04-13 10:05:27.730073|[INITIALIZER][LedgerInitializer]initLedger failed,EINFO=/root/FISCO-BCOS/libinitializer/LedgerInitializer.cpp(126): Throw in function dev::initializer::LedgerInitializer::initLedgers()::<lambda(const GROUP_ID&, const string&)>
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >
std::exception::what: std::exception
error|2023-04-13 10:05:27.730244|[INITIALIZER][Initializer]Init failed,EINFO=/root/FISCO-BCOS/libinitializer/LedgerInitializer.cpp(136): Throw in function std::vector<short int> dev::initializer::LedgerInitializer::initLedgers()
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::exception> >
std::exception::what: std::exception
是因为没有安装snappy库,执行sudo apt install libsnappy-dev
安装后重新编译librocksdb.a
文件即可。