I'm struggling to compile some code that utilises the boost property tree. I'm using Visual Studio 2010.
If I simplify the code as much as possible to reproduce the error, the code looks like the following...
#include "AppleiTunesLibraryImporter.h"
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
using namespace boost::property_tree;
AppleiTunesLibraryImporter::AppleiTunesLibraryImporter(){}
AppleiTunesLibraryImporter::~AppleiTunesLibraryImporter(){}
bool AppleiTunesLibraryImporter::ImportData( std::string itunes_library_xml_path )
{
ptree pt;
xml_parser::read_xml( itunes_library_xml_path.c_str(), pt, xml_parser::no_comments | xml_parser::trim_whitespace);
return true;
}
...and the full error looks like the following...
1> AppleiTunesLibraryImporter.cpp
1>c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/detail/allocator_utilities.hpp(178): error C2061: syntax error : identifier 'p'
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/detail/index_base.hpp(88) : see reference to function template instantiation 'void boost::detail::allocator::construct<T>(void *,const Type &)' being compiled
1> with
1> [
1> T=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1> Type=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/detail/index_base.hpp(87) : while compiling class template member function 'boost::multi_index::detail::index_node_base<Value,Allocator> *boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>::insert_(const std::pair<_Ty1,_Ty2> &,boost::multi_index::detail::index_node_base<Value,Allocator> *)'
1> with
1> [
1> Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1> Allocator=std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>,
1> IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,
1> _Ty1=const std::string,
1> _Ty2=boost::property_tree::basic_ptree<std::string,std::string>
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/ordered_index.hpp(119) : see reference to class template instantiation 'boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>' being compiled
1> with
1> [
1> Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1> IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,
1> Allocator=std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/sequenced_index.hpp(77) : see reference to class template instantiation 'boost::multi_index::detail::ordered_index<KeyFromValue,Compare,SuperMeta,TagList,Category>' being compiled
1> with
1> [
1> KeyFromValue=boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,
1> Compare=std::less<std::string>,
1> SuperMeta=boost::multi_index::detail::nth_layer<2,std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>>,
1> TagList=boost::mpl::vector1<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,
1> Category=boost::multi_index::detail::ordered_non_unique_tag
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index_container.hpp(89) : see reference to class template instantiation 'boost::multi_index::detail::sequenced_index<SuperMeta,TagList>' being compiled
1> with
1> [
1> SuperMeta=boost::multi_index::detail::nth_layer<1,std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>>,
1> TagList=boost::mpl::vector0<boost::mpl::na>
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(59) : see reference to class template instantiation 'boost::multi_index::multi_index_container<Value,IndexSpecifierList>' being compiled
1> with
1> [
1> Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1> IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(182) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>::subs' being compiled
1> with
1> [
1> Key=std::string,
1> Data=std::string
1> ]
1> c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(182) : while compiling class template member function 'boost::property_tree::basic_ptree<Key,Data>::basic_ptree(void)'
1> with
1> [
1> Key=std::string,
1> Data=std::string
1> ]
1> ..\..\..\common\Source\AppleiTunesImporter\AppleiTunesLibraryImporter.cpp(24) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>' being compiled
1> with
1> [
1> Key=std::string,
1> Data=std::string
1> ]
For me, line 24 of my ApplieiTunesLibraryImporter.cpp file is just
ptree pt;
so, the compiler is not liking my use of it. I can get similar errors when I use something like
ptree::const_assoc_iterator assoc_iter;
but the above code is the simplest I can make the error happen.
The code inside the boost file (allocator_utilities.hpp) that is causing the compilation error looks like the following, but it's quite cryptic to me.
/* allocator-independent versions of construct and destroy */
template<typename Type>
void construct(void* p,const Type& t)
{
new (p) Type(t);
}
In case someone wants to try and reproduce, here is the .h code.
class AppleiTunesLibraryImporter
{
public:
AppleiTunesLibraryImporter();
virtual ~AppleiTunesLibraryImporter();
bool ImportData( std::string itunes_library_xml_path );
};
This has all turned into a bit of brain melt so if anyone can shed some light on this, it would be greatly appreciated.
Cheers.
I've found the problem. The project I'm working on makes use of precompiled headers and for the .cpp files that are using boost libs, I had to prevent this from happening. In other words, I had to right click on the .cpp file an go...
Properties > Configuration Properties > C/C++ > Precompiled Headers
and set "Precompiled Headers" to "Not Using Precompiled Headers" Also, go to...
Properties > Configuration Properties > C/C++ > Advanced
and set "Forced Include File" to nothing.