Opened 9 years ago

Last modified 7 years ago

#8634 new Bugs

boost/filesystem/path.hpp is not self-sufficient

Reported by: Valentin Shtronda <valiko.ua@…> Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

The following code is compiled under VC2012:

#include <boost/filesystem.hpp>
boost::filesystem::path p("file.txt");
size_t hash = boost::filesystem::hash_value(p);

but gives link error:

error LNK2019: unresolved external symbol "void __cdecl boost::hash_combine<wchar_t>(unsigned int &,wchar_t const &)" (??$hash_combine@_W@boost@@YAXAAIAB_W@Z) referenced in function "unsigned int __cdecl boost::filesystem::hash_value(class boost::filesystem::path const &)" (?hash_value@filesystem@boost@@YAIABVpath@12@@Z)

I fixed it by replacing

#include <boost/functional/hash_fwd.hpp>

with

#include <boost/functional/hash.hpp>

Change History (1)

comment:1 by keen.benjamin.j@…, 7 years ago

Problem still exists on 1.60.0, gcc 5.3.0 x86_64-unknown-linux-gnu (CentOS 7)

// if #include <boost/functional/hash.hpp> absent, link error on boost::filesystem::hash_range
// if present, no problem.
// #include <boost/functional/hash.hpp> 
#include <boost/filesystem.hpp>

namespace std {
    template <> struct hash<boost::filesystem::path>
    {
        size_t operator()(const boost::filesystem::path& p) const
        {
            return boost::filesystem::hash_value(p);
        }
    };
}

For that matter, shouldn't the boost header put this specialization in the std:: namespace anyway?

Note: See TracTickets for help on using tickets.