|
Boost : |
Subject: Re: [boost] [filesystem][iostreams][program_options] linker issues on msvc
From: Alexander Arhipenko (arhipjan_at_[hidden])
Date: 2009-11-21 07:10:45
On Sat, Nov 21, 2009 at 11:20 AM, Vladimir Prus
<vladimir_at_[hidden]> wrote:
> Alexander Arhipenko wrote:
>
>>
>>
>> Index: libs/filesystem/build/Jamfile.v2
>> ===================================================================
>> --- libs/filesystem/build/Jamfile.v2 (revision 57802)
>> +++ libs/filesystem/build/Jamfile.v2 (working copy)
>> @@ -11,6 +11,7 @@
>> project boost/filesystem
>> : source-location ../src
>> : usage-requirements # pass these requirement to dependents (i.e. users)
>> + <library>/boost/system
>> <link>shared:<define>BOOST_FILESYSTEM_DYN_LINK=1
>> <link>static:<define>BOOST_FILESYSTEM_STATIC_LINK=1
>> ;
>
> Alexander,
> do you actually need the above patch? Because boost.filesystem has boost.system
> in sources, you should not need to add it to usage requirements.
>
> Could you clarify?
>
> I have checked in two other changes in your patch. Thanks!
>
> - Volodya
>
Hi Volodya,
I thinks the filesystem's patch is required and will try to clarify why.
Here is minimal example that reproduces the issue:
#Jamfile.v2:
exe foo : main.cpp /boost/filesystem ;
//main.cpp:
#include <boost/filesystem.hpp>
int main(int argc, char* argv)
{
return 0;
}
In this case following error appears:
main.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) class boost::system::error_category const &
__cdecl boost::system::get_system_category(void)"
(__imp_?get_system_category_at_system@boost@@YAABVerror_category_at_12@XZ)
referenced in function "void __cdecl boost::system::`dynamic
initializer for 'system_category''(void)"
(??__Esystem_category_at_system@boost@@YAXXZ)
The reason is:
#include <boost/filesystem.hpp> --> includes <boost/path.hpp> -->
includes <boost/system/system_error.hpp> --> includes
<boost/system/error_code.hpp>
File boost/system/error_code.hpp has following declarations:
BOOST_SYSTEM_DECL const error_category & get_system_category();
BOOST_SYSTEM_DECL const error_category & get_generic_category();
So, when the header above is included in main.cpp, BOOST_SYSTEM_DECL unrolls to:
__declspec(dllimport).
And this causes the linker error.
As a result, library that links boost::filesystem should link boost::system.
Regards
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk