[版权声明] 本站内容采用 知识共享署名-非商业性使用-相同方式共享 3.0 中国大陆 (CC BY-NC-SA 3.0 CN) 进行许可。
部分内容和资源来自网络,纯学习研究使用。如有侵犯您的权益,请及时联系我,我将尽快处理。
如转载请注明来自: Broly的博客,本文链接: glog编译错误:error: ‘GFLAGS_NAMESPACE’ is not a namespace-name
截止至今天,google glog在Github提供的最新release提供的版本是0.3.5。按照官方提供的编译方法,编译失败了。
编译步骤:
1 2 3 4 5 |
cd ~ wget -O glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz tar zxvf glog-0.3.5.tar.gz cd glog-0.3.5 ./autogen.sh |
碰到的第一个问题是,找不到autogen.sh文件。
看了下master分支是有这个文件的,但是发布的release包确实没有这个文件,所以我先跳过这个文件,把这行命令注释了。
继续执行
1 2 |
./configure --prefix=`pwd`/../glog make |
结果报新的错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
src/logging_unittest.cc:64:17: error: ‘GFLAGS_NAMESPACE’ is not a namespace-name using namespace GFLAGS_NAMESPACE; ^ src/logging_unittest.cc:64:33: error: expected namespace-name before ‘;’ token using namespace GFLAGS_NAMESPACE; ^ src/logging_unittest.cc: In function ‘int main(int, char**)’: src/logging_unittest.cc:180:43: error: ‘ParseCommandLineFlags’ was not declared in this scope ParseCommandLineFlags(&argc, &argv, true); src/logging_unittest.cc:180:43: note: suggested alternative: In file included from src/glog/logging.h:86:0, from src/utilities.h:82, from src/logging_unittest.cc:33: /usr/include/gflags/gflags.h:346:31: note: ‘gflags::ParseCommandLineFlags’ extern GFLAGS_DLL_DECL uint32 ParseCommandLineFlags(int *argc, char*** argv, bool remove_flags); |
glog是依赖gflags库的,从错误提示中可以看到,编译的时候是调用了系统安装的gflags库(不知道自带的还是我后来自己yum安装的),结果有不兼容。所以我决定自己编译一个gflags库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 卸载系统的gflags sudo yum remove -y gflags-devel # 下载编译gflags cd ~ wget -O gflags-2.2.1.tar.gz https://github.com/gflags/gflags/archive/v2.2.1.tar.gz tar zxvf gflags-2.2.1.tar.gz cd gflags-2.2.1 mkdir -p build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=`pwd`/../../gflags make make install cd ~/glog-0.3.5 ./configure --prefix=`pwd`/../glog --includedir=~/gflags/include make make install |
最后编译成功没有报错啦~