google的gflags:
CMakeList.txt:
cmake_minimum_required(VERSION 2.8.0)
project(info)
add_executable(${PROJECT_NAME}
test.cpp
)
target_link_libraries(${PROJECT_NAME}
pthread
tinyxml2
gflags
-lm
)
test.cpp
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <thread>
#include <unistd.h>
#include <memory>
#include <stdio.h>
#include <tinyxml2.h>
#include <cstdlib>
#include <math.h>
#include <gflags/gflags.h>
using namespace std;
DEFINE_bool(foo, true, "");
DEFINE_double(thread, 10, "");
int main(int argc, char **argv)
{
//google::ParseCommandLineFlags(&argc, &argv, true);
std::string flag_file_path = "/home/li/Desktop/test/test.conf";
google::SetCommandLineOption("flagfile", flag_file_path.c_str());
if(FLAGS_foo)
{
std::cout << "1" << std::endl;
}
else
{
std::cout << "2" << std::endl;
}
std::cout << "thread" << FLAGS_thread << std::endl;
return 0;
}
test.conf
-foo=false
-thread=89