文章目录
reference
卸载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