0、系统环境
Ubuntu 16.04
GCC 5.4
1、安装步骤
1)安装 GFlags
运行如下指令:
|
1
2
3
4
5
6
|
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
|
2)安装 GLog:
安装编译工具:
|
1
|
sudo apt-get install autoconf automake libtool
|
运行如下指令安装:
|
1
2
3
4
5
|
git clone https://github.com/google/glog
./autogen.sh
./configure
make -j8
sudo make install
|
常见问题
1、使用 GLog 报错:libglog.a: error adding symbols: Bad value
在使用 GLog 的工程中遇到了如下错误:
|
1
2
3
|
/usr/bin/ld: /usr/local/lib/libglog.a(libglog_la-logging.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libglog.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
|
产生该问题的可能原因是在 64位系统中,不能链接 GLog 生成动态库。修改方法是 GLog 需要使用如下方式编译,加入 -fPIC 编译选项:
|
1
|
./configure CPPFLAGS="-I/usr/local/include -fPIC" LDFLAGS="-L/usr/local/lib"
|
代替:
|
1
|
./configure
|
2、错误:undefined reference to `google::FlagRegisterer::FlagRegisterer
如果你在编译 GLog 时遇到如下错误:
|
1
|
undefined reference to 'google::FlagRegisterer::FlagRegisterer'
|
可以尝试先卸载 GFlags:
|
1
|
sudo apt-get purge libgflags-dev
|
然后重新编译
另一种可能的解决方案是,在编译 GLog 时请使用:
|
1
|
./configure CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
|
代替:
|
1
|
./configure
|
3、错误:Make error: failed to link with libgflags.a
产生该问题的原因有可能是需要使用动态库方式编译 GFlags
将 GFlags 编译时选项改成动态库:
|
1
|
cmake .. -DBUILD_SHARED_LIBS=ON
|
并重新编译 GFlags 和 GLog。
4、错误:something wrong with flag ‘flagfile’ in file ‘XXX.cc’
请参照 3 中的解决方案重新编译 GFlags 和 GLog。
