folly庫的安裝-Ubuntu18.04

版權聲明:原創文章,歡迎轉載,但請註明出處,謝謝。 https://blog.csdn.net/qiuguolu1108/article/details/106445831

folly庫是facebook的一個C++基礎庫。

一、環境

本文使用Ubuntu18.04安裝folly庫,g++和cmake的版本如下:

root@learner:~# g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

root@learner:~# cmake --version
cmake version 3.10.2

注意:g++需要支持C++14

二、安裝依賴

googletest的安裝
wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz && \
tar zxf release-1.8.0.tar.gz && \
rm -f release-1.8.0.tar.gz && \
cd googletest-release-1.8.0 && \
cmake . && \
make && \
make install
安裝下列的package
sudo apt-get install \
    g++ \
    cmake \
    libboost-all-dev \
    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
安裝fmt
git clone https://github.com/fmtlib/fmt.git && cd fmt

mkdir _build && cd _build
cmake ..

make -j$(nproc)
sudo make install
安裝調試相關的依賴
apt-get install \
    libunwind8-dev \
    libelf-dev \
    libdwarf-dev

三、下載安裝folly

folly的github地址:https://github.com/facebook/folly

下載folly
git clone https://github.com/facebook/folly.git
編譯安裝folly
cd folly
mkdir _build && cd _build
cmake ..
make -j $(nproc)
make install 

folly庫安裝完成了,下面寫個小程序測試一下。

四、測試

#include <folly/concurrency/ConcurrentHashMap.h>
#include <string>
#include <iostream>

class Student 
{
public:
    Student(std::string name, int id, std::string email)
        : m_name(name), m_id(id), m_email(email)
    {}

    void printSelf() const 
    {
        std::cout << "name: " << m_name << " "
            << "id: " << m_id << " "
            << "email: " << m_email << std::endl;
    }

private:
    std::string m_name;
    int m_id;
    std::string m_email;
};

int main() 
{
    folly::ConcurrentHashMap<std::string, Student> students;
    students.insert("Tom", Student("Tom", 1, "[email protected]"));
    students.insert("Lilly", Student("Lilly", 2, "[email protected]"));

    for (const auto& st : students) 
    {
        st.second.printSelf();
    }
    
    return 0;
}
root@learner:~# g++ hashmap.cpp -lfolly -lglog -lgflags -lpthread -ldl -ldouble-conversion -liberty
root@learner:~# ./a.out 
name: Tom id: 1 email: [email protected]
name: Lilly id: 2 email: [email protected]

運行成功~~~

示例複製自:https://www.cnblogs.com/albizzia/p/10824721.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章