glog&gflags 卸載與安裝

reference

卸載教程
gflags安裝

卸載glog

使用locate命令獲得相關路徑

~$ locate glog |grep /usr
/usr/local/include/glog
/usr/local/include/glog/config.h
/usr/local/include/glog/log_severity.h
/usr/local/include/glog/logging.h
/usr/local/include/glog/raw_logging.h
/usr/local/include/glog/stl_logging.h
/usr/local/include/glog/vlog_is_on.h
/usr/local/x86_64-linux-gnu/libglog.a
/usr/local/x86_64-linux-gnu/cmake/glog

刪除頭文件 & 庫文件

# 刪頭文件
sudo rm -rf /usr/local/include/glog/
# 刪庫文件
sudo rm -rf /usr/local/x86_64-linux-gnu/libglog*

安裝glog

先卸載gflags

locate gflags|grep /usr

查找下相關位置
類似卸載glog的方法卸載它

安裝glog

git clone https://github.com/google/glog
./autogen.sh
./configure
make -j 32
sudo make install

安裝gflags 【其實也可以不安 – 沒有必要的話就別安裝了… 】

git clone https://github.com/gflags/gflags.git
cd gflags
mkdir build && cd build
cmake .. -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC ..
make -j4
sudo make install

如果出現undefined reference to `google::FlagRegisterer::FlagRegisterer 可以refer to this

測試是否成功

測試代碼

//#include <gflags/gflags.h>
#include <glog/logging.h>
#include<iostream>

//DEFINE_string(hosts, "127.0.0.1", "the server host");
//DEFINE_int32(ports, 12306, "the server port");

int main(int argc, char** argv) {
    // 解析命令行參數,一般都放在 main 函數中開始位置
    //google::ParseCommandLineFlags(&argc, &argv, true);
    std::string host = "127.0.0.1";
    int port =32;
    LOG(INFO)<<"nihao";
    // 訪問參數變量,加上 FLAGS_
    std::cout << "The server host is: " << host
        << ", the server port is: " << port << std::endl;
    return 0;
}

把註釋刪掉的話就可以連同gflags一起測試

  • 如果遇到如下報錯

error while loading shared libraries: libglog.so.0: cannot open shared object file: No such file or directory

不要慌,試試ldconifg

測試命令

g++ test.cc -lglog -o test
# 刪掉註釋連同gflagss一起測試
g++ test.cc -lglog -lgflags -lpthread -o test
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章