Linker error with boost filesystem

Help
GaryE
2007-05-23
2013-05-14
  • GaryE
    GaryE
    2007-05-23

    Hello:
    I am having trouble linking a couple of files using the boost::filesystem.
    Here is an abbreviated version of my problem:
    foo.h:
    #ifndef __FOO_
    #define __FOO_
    #include "boost/filesystem.hpp"
    class foo
    {
    public
    /*stuff*/
    private
    boost::filesystem::path m_path;
    };
    #endif

    bar.h:
    #ifndef __BAR_
    #define __BAR_
    class foo;
    class bar
    {
    public
    /*stuff*/
    private
    foo m_foo;
    };
    #endif

    bar.cpp:
    #include "foo.h"
    /*use foo a lot*/

    build result:
    bar.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::filesystem::extension(class boost::filesystem::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem::path_traits> const &)" (?extension@filesystem@boost@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem@boost@@@12@@Z) already defined in foo.obj
    bar.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl boost::filesystem::basename(class boost::filesystem::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem::path_traits> const &)" (?basename@filesystem@boost@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem@boost@@@12@@Z) already defined in foo.obj
    Debug/FooBar.exe : fatal error LNK1169: one or more multiply defined symbols found

    Any ideas on what the problem is?
    I am using MSVC 6.0.
    Thanks