Anders,

It is somewhat relevant to OSG too, in that linking against osgDB and other 
code that uses <fstream> will cause similar 'multiple-defined'  linker errors.  
This problem seems to be only with MSVC2010, the OS doesn't seem to matter (I 
use XP).  osgDB is affected because of osgDB::fstream, which subclasses from 
std::fstream.  The current workaround is to allow multiple symbols when 
linking.  I would be interested in finding a better solution to this problem...

Chuck


On Aug 26, 2010, at 9:35 AM, Anders Backman wrote:

> Hi all.
> 
> This is not related to OSG in any way, but as there so many experts on the 
> list, I thought I should take the opportunity to ask this...
> 
> I have a problem related to linking in VS2010.
> 
> Im using VS2010 under Windows 7 (64).
> 
> Im building a large source package which is divided into two separate 
> libraries (dynamic linking: .lib, .dll).
> 
> in the first library, a.lib we are using both std::stringstream and 
> std::ostringstream. a.lib depends on other libraries, all built by myself 
> using CMake and VS2010. CMake defaults to /MD code generation 
> (MultiThreaded). Im using this consistently over all my libraries (just 
> double checked to be sure).
> 
> When I build the next library, b.lib, which depends on a.lib, I get the 
> following linking errors:
> 
> 
> 
> Linking of b.lib:
> 
> 1>a.lib(a.dll) : error LNK2005: "public: void __thiscall 
> std::basic_ostringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::`vbase destructor'(void)" 
> (??_d?$basic_ostringstr...@du?$char_traits@d...@std@@v?$alloca...@d@2@@std@@QAEXXZ)
>  already defined in ImageCapture.obj
> 
> 
> 1>a.lib(a.dll) : error LNK2005: "public: class std::basic_string<char,struct 
> std::char_traits<char>,class std::allocator<char> > __thiscall 
> std::basic_ostringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::str(void)const " 
> (?...@?$basic_ostringstream@du?$char_tra...@d@std@@v?$alloca...@d@2@@std@@qbe?av?$basic_str...@du?$char_traits@d...@std@@v?$alloca...@d@2@@2...@xz)
>  already defined in ImageCapture.obj
> 
> 1>a.lib(a.dll) : error LNK2005: "public: __thiscall 
> std::basic_ostringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::basic_ostringstream<char,struct 
> std::char_traits<char>,class std::allocator<char> >(int)" 
> (??0?$basic_ostringstr...@du?$char_traits@d...@std@@v?$alloca...@d@2@@std@@q...@h@Z)
>  already defined in ImageCapture.obj
> 
> 
>  
> Ok, I go into the sourcecode of ImageCapture.cpp and remove the use of 
> std::ostringstream.
> 
> And everything builds.
> 
> Next, I try to use std::ostringstream in some other cpp file of the b.lib, so 
> I just copy the code from ImageCapture.cpp into another .cpp file in b.lib, 
> including the #include directives...
> 
> It links just fine.
> 
>  
> 
> One important thing to mention, all of this works just fine in VS2008.
> 
> 
> 
> Next, I tried to change from std::ostringstream to std::stringstream in both 
> a.lib AND b.lib.
> 
>  
> Now I get the same error, but instead its std::stringstream mentioned in the 
> error message:
> 
>  
> 
> 2>a.lib(a.dll) : error LNK2005: "public: void __thiscall 
> std::basic_stringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::`vbase destructor'(void)" 
> (??_d?$basic_stringstr...@du?$char_traits@d...@std@@v?$alloca...@d@2@@std@@QAEXXZ)
>  already defined in ImageCapture.obj
> 
> 2>a.lib(a.dll) : error LNK2005: "public: class std::basic_string<char,struct 
> std::char_traits<char>,class std::allocator<char> > __thiscall 
> std::basic_stringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::str(void)const " 
> (?...@?$basic_stringstream@du?$char_tra...@d@std@@v?$alloca...@d@2@@std@@qbe?av?$basic_str...@du?$char_traits@d...@std@@v?$alloca...@d@2@@2...@xz)
>  already defined in ImageCapture.obj
> 
> 2>a.lib(a.dll) : error LNK2005: "public: __thiscall 
> std::basic_stringstream<char,struct std::char_traits<char>,class 
> std::allocator<char> >::basic_stringstream<char,struct 
> std::char_traits<char>,class std::allocator<char> >(int)" 
> (??0?$basic_stringstr...@du?$char_traits@d...@std@@v?$alloca...@d@2@@std@@q...@h@Z)
>  already defined in ImageCapture.obj
> 
> 
> So, the situation is exactly the same, its just changed from 
> std::ostringstream to std::stringstream.
> 
> If I have just the right balance between stringstream and ostringstream, it 
> builds. Then the problem occurs when I want to build a third library, 
> depending on both a.lib AND b.lib...
> 
> Then it starts all over.
> 
> The next thing I did was to generate project files for vs2008, build with 
> vs2008 (using dependencies built with vs2010), compiles/links just fine. 
> Except it does not run (incompatible STL, crash in deque).
> 
> Ok, so it builds in VS2008. Next was to build everything in vs2010 using the 
> same project files. Then I get the above linking error.
> 
> 
> 
> Im more and more leaning towards a bug in VS2010, but its really hard to 
> verify...
> 
> 
> Anyone experienced this in VS2010?
> 
>  -
> 
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to