By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

linker error building code with boost filesystem

P: 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
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
You need to #include <string>.
May 25 '07 #2

P: 3
Thanks, but that still doesn't work.
May 25 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
And you have:

Expand|Select|Wrap|Line Numbers
  1. using namespace std;
  2.  
Yes?
May 27 '07 #4

P: 3
Yes. This makes no difference.
May 31 '07 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
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.