'Issue when using property_tree for a ini file

Strange error when compiling with property tree to write and read a ini (text) file. Simple standalone program(MSVP) works fine. But when i include it in my main code, I get this error. What could this mean ?

It looks like it is not happy with me including

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>

When I comment them out, this error goes away. I have -lboost_system in my LD_LIBS. Would ptree come under boost_system library or could it be any other library that I should include ?

In file included from /home/badri/usr/include/boost/property_tree/ptree.hpp:516,
                 from recorder_apis.h:15,
                 from recorder_apis.cpp:1:
/home/badri/usr/include/boost/property_tree/detail/ptree_implementation.hpp: In member function ‘boost::property_tree::basic_ptree<K, D, C>& boost::property_tree::basic_ptree<Key, Data, KeyCompare>::get_child(const path_type&)’:
/home/badri/usr/include/boost/property_tree/detail/ptree_implementation.hpp:571:58: error: declaration of ‘path’ shadows a global declaration [-Werror=shadow]
  571 |         basic_ptree<K, D, C>::get_child(const path_type &path)
      |                                         ~~~~~~~~~~~~~~~~~^~~~
In file included from /home/badri/usr/include/boost/property_tree/ptree.hpp:15,
                 from recorder_apis.h:15,
                 from recorder_apis.cpp:1:
/home/badri/usr/include/boost/property_tree/ptree_fwd.hpp:89:67: note: shadowed declaration is here
   89 |     typedef string_path<std::string, id_translator<std::string> > path;
      |                                                                   ^~~~

I am only using the boost library. So I don't deal with the files ptree_fwd.hpp or ptree_implementation.hpp directly in anyway.

MSVP that works fine

#include<iostream>
#include<boost/property_tree/ptree.hpp>
#include<boost/property_tree/ini_parser.hpp>

using namespace std;
int main()
{
        using boost::property_tree::ptree;
        ptree pt;

        std::string jobToken1="123";
        std::string jobToken2="234";
        std::string jobToken3="345";

        pt.put("General.Token", "rec1");
        pt.put("General.Location", "/media/sd1/abc_1");

        pt.put(jobToken1+".startTime", 123456);
        pt.put(jobToken1+".endTime", 345678);

        pt.put(jobToken2+".startTime", 123456);
        pt.put(jobToken2+".endTime", 345678);

        pt.put(jobToken3+".startTime", 123456);
        pt.put(jobToken3+".endTime", 345678);


        write_ini("input.txt", pt);

        read_ini("input.txt", pt);

        for(auto& section : pt)
        {
                cout << "[" << section.first << "]\n";
                for (auto& key: section.second)
                        cout << key.first << "=" << key.second.get_value<string>() <<"\n";
        }
}
~    


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source