我安装了gflags:
$ ls /usr/local/lib/ | grep gflags
libgflags.a
libgflags_nothreads.a
$ ls /usr/local/include/ | grep gflags
gflags
并包括<gflags/gflags.h>
#include <gflags/gflags.h>
DEFINE_bool(a, false, "test");
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
return 0;
}
但我得到了一个链接器错误!
$ g++ -lgflags a.cpp
/tmp/cchKYAWZ.o: In function `main':
/home/wonter/gflags-2.2.1/build/a.cpp:6: undefined reference to `google::ParseCommandLineFlags(int*, char***, bool)'
/tmp/cchKYAWZ.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/wonter/gflags-2.2.1/build/a.cpp:3: undefined reference to `google::FlagRegisterer::FlagRegisterer<bool>(char const*, char const*, char const*, bool*, bool*)'
collect2: error: ld returned 1 exit status
我试过$ g++ /usr/local/lib/libgflags.a a.cpp -o test
了,但得到了同样的错误。
我的平台是Ubuntu 17.10
,GCC版本是gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)
难道是因为我的GCC版本的问题?