470,819 Members | 1,602 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

linker error building code with boost filesystem

3
Hello:
I am having trouble linking a couple of files using the boost::filesystem.
I am using MSVC 6.0.
Here is an abbreviated version of my problem:

foo.h:
Expand|Select|Wrap|Line Numbers
  1. #ifndef __FOO_ 
  2. #define __FOO_ 
  3. #include "boost/filesystem.hpp" 
  4. class foo 
  5. public 
  6. /*stuff*/ 
  7. private 
  8. boost::filesystem::path m_path; 
  9. }; 
  10. #endif 
  11.  
bar.h:
Expand|Select|Wrap|Line Numbers
  1. #ifndef __BAR_ 
  2. #define __BAR_ 
  3. class foo; 
  4. class bar 
  5. public 
  6. /*stuff*/ 
  7. private 
  8. foo* m_fooPtr; 
  9. }; 
  10. #endif 
  11.  
bar.cpp:
Expand|Select|Wrap|Line Numbers
  1. #include "foo.h" 
  2. /*use foo a lot*/ 
  3.  
  4.  
Here is the 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@bo ost@@@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@D U?$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@boo st@@@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?
Thanks
May 25 '07 #1
5 3131
weaknessforcats
9,208 Expert Mod 8TB
You need to #include <string>.
May 25 '07 #2
GaryE
3
Thanks, but that still doesn't work.
May 25 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
And you have:

Expand|Select|Wrap|Line Numbers
  1. using namespace std;
  2.  
Yes?
May 27 '07 #4
GaryE
3
Yes. This makes no difference.
May 31 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. boost::filesystem::path m_path; 
  2.  
requires a class or namespace named boost plus a nestted class or namespace named filesystem plsu a nested class or namespace named path.

What does this thing have in it?

Expand|Select|Wrap|Line Numbers
  1. #include "boost/filesystem.hpp" 
  2.  
Also, I would like to see the entire bar.cpp since that is what is being compiled.
May 31 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by jhasse | last post: by
1 post views Thread by toton | last post: by
4 posts views Thread by Gary Wessle | last post: by
1 post views Thread by Lawrence Spector | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.