This is the linker error I'm getting. All the rest of my boost::filesystem things are resolving. I'm not understanding why this one does not. I thought it was a problem with boost 1.40, so I upgraded to 1.44 and the problem remains. I'm using #define BOOST_FILESYSTEM_VERSION 3
but I see no mention of last_write_time not being provided in that case. It seems the underlying implementation is missing, even though the api portion is present.
1>TestPruner.obj : error LNK2019: unresolved external symbol "void __cdecl boost::filesystem3::detail::last_write_time(class boost::filesystem3::path const &,long,class boost::system::error_code *)" (?last_write_time@detail@filesystem3@boost@@YAXABVpath@23@JPAVerror_code@system@3@@Z) referenced in fu开发者_运维百科nction "void __cdecl boost::filesystem3::last_write_time(class boost::filesystem3::path const &,long)" (?last_write_time@filesystem3@boost@@YAXABVpath@12@J@Z)
Oh yea, using Windows VS2008.
The code involved is:
time_t curTime = time(NULL);
bfs::last_write_time(bfs::path("TestData/PruneTest/completed/Batch001.DAT"), curTime);
Anyone else run into this?
And it happens with #define BOOST_FILESYSTEM_VERSION 2
as well. The Boost libraries I'm using are from boostpro (prebuilt, yea, I'm lazy)
2>TestPruner.obj : error LNK2019: unresolved external symbol "class boost::system::error_code __cdecl boost::filesystem2::detail::last_write_time_api(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,long)" (?last_write_time_api@detail@filesystem2@boost@@YA?AVerror_code@system@3@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@J@Z) referenced in function "void __cdecl boost::filesystem2::last_write_time<class boost::filesystem2::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem2::path_traits> >(class boost::filesystem2::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem2::path_traits> const &,long)" (??$last_write_time@V?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem2@boost@@@filesystem2@boost@@@filesystem2@boost@@YAXABV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem2@boost@@@01@J@Z)
From /versbose:lib
Searching e:\Program Files\boost\boost_1_44\lib\libboost_thread-vc90-mt-gd-1_44.lib:
Searching e:\Program Files\boost\boost_1_44\lib\libboost_date_time-vc90-mt-gd-1_44.lib:
Ok, the problem is as simple as it is obtuse. In VS2008 and above time_t is 64 bits, unless you #define _USE_32_BIT_TIME_T
. The boost libraries are compiled without this definition and therefore time_t is 64 bits for them. My project due to some legacy issues does define _USE_32_BIT_TIME_T and therefore generates the API with a 32 bit time.
If you build a project that doesn't use 32 bit time, it works as expected.
I'm glad the C++ guys were smart enough to push the call signature into the linker with name mangling. If they hadn't done that, I'd still be wondering what was going on.
I wonder if this is so much a problem with the function as with the function arguments. Looking through the boost::filesystem api, I couldn't find a last_write_detail function with both Path and time arguments, only a Path argument. On the other hand I did find
last_write_time_api( const std::string & ph, std::time_t new_value );
as opposed to
BOOST_FS_FUNC(std::time_t) last_write_time( const Path & ph )
So maybe the error is because the linker can't find a version of the function with the right signature, and you should be using last_write_time_api instead?
精彩评论