17

在 Ubuntu 上安装 Facebook 的 C++ 库 Folly

 4 years ago
source link: https://zhiqiang.org/coding/folly-install-on-ubuntu.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在 Ubuntu 上安装 Facebook 的 C++ 库 Folly

作者: 张志强

, 发表于 2019-08-01

, 共 2316 字 , 共阅读 592 次

Folly 官方地址:https://github.com/facebook/folly

folly 依赖格式化库fmt,需手工安装:

cd ~/3rd;
git clone https://github.com/fmtlib/fmt.git && cd fmt

mkdir _build && cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE

make -j$(nproc)
sudo make install

下面脚本下载库文件到~/3rd,编译安装到/opt/include/opt/lib

cd ~/3rd;
sudo apt-get install g++ cmake libevent-dev libdouble-conversion-dev libgoogle-glog-dev libgflags-dev libiberty-dev liblz4-dev liblzma-dev libsnappy-dev make zlib1g-dev binutils-dev libjemalloc-dev libssl-dev pkg-config libunwind-dev unzip -y

wget https://github.com/facebook/folly/archive/master.zip -O folly.zip
unzip folly.zip
cd folly-master
mkdir _build && cd _build
cmake .. "-DCMAKE_INCLUDE_PATH=/opt/include" "-DCMAKE_LIBRARY_PATH=/opt/lib" -DCMAKE_INSTALL_PREFIX=/opt/ -DFOLLY_SUPPORT_SHARED_LIBRARY=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
make -j
make install  # /opt

folly编译后只有一个libfolly.a库文件,该文件不能用于构建SO文件,会报类似于下面的错误:

/usr/bin/ld: /opt/lib/libfolly.a(F14Table.cpp.o): relocation R_X86_64_TPOFF32 against `_ZZN5folly3f146detail21tlsPendingSafeInsertsElE5value' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /opt/lib/libfolly.a(dynamic.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN5folly7dynamic8typeNameENS0_4TypeE' can not be used when making a shared object; recompile with -fPIC

下面方法可支持构建SO文件:

cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON

其它还可能碰到的错误为:

/usr/bin/ld: warning: libaio.so.1, needed by /opt/lib/libfolly.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libunwind.so.1, needed by /opt/lib/libfolly.so, not found (try using -rpath or -rpath-link)
/opt/lib/libfolly.so: undefined reference to `io_getevents@LIBAIO_0.4'
/opt/lib/libfolly.so: undefined reference to `io_queue_init@LIBAIO_0.1'
/opt/lib/libfolly.so: undefined reference to `io_submit@LIBAIO_0.1'
/opt/lib/libfolly.so: undefined reference to `io_queue_release@LIBAIO_0.1'

本质原因是libfolly.so找不到libaio.solibunwind.so库文件。这可以用命令ldd /your_path/libfolly.so看出来。可以从其它机器将这两个文件复制过来,位置位于:

  • /lib/x86_64-linux-gnu/libaio.so.1.0.1
  • /lib/x86_64-linux-gnu/libaio.so.1 (只是上面文件的软链接)
  • /usr/local/lib/libunwind.so.1

注意: ubuntu 20.04 unwind 版本为 libunwind.so.8

Q. E. D.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK