Error when linking: msvcprtd.lib(MSVCP90D.dll) : error LNK2005 ….. already defined in libalglib.li

Hello,
I am a totally newbie and I would be pleased, if you could help me.

Here is the problem: I have created VS 2008 project and configured it for using the ITK (toolkit for medical image analysis – in my case for reading Dicom images). Everything worked OK until I added ALGLIB to my project (library for algebraic operations – it is one file: libalglib.lib and a few .h files for include). Here comes the problem: when I tried to compile and link my project with this ALGLIB library, I got these errors and I dont know what to do (tried different Runtime library settings etc., nothing helped).

I assume, that it could be some conflict with ITK and ALGLIB – when I comment part of my code using ITK, everythnig works well (ALGLIB works ok) and when I comment part of my code using ALGLIB, everything works as well too (ITK works ok).

Here are the errors:

1>Linking...
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)"
 ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::operator=(char const *)"
 ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits::length(char const *)"
 ([email protected][email protected]@[email protected]@[email protected]) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string,class std::allocator >::size(void)const "
 ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@QBEIXZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(class std::basic_string,class std::allocator > const &)"
 ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::erase(unsigned int,unsigned int)"
 ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator::allocator(void)"
 ([email protected]@[email protected]@[email protected]) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::allocator::deallocate(char *,unsigned int)"
 ([email protected][email protected]@[email protected]@[email protected]) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator::allocator(class std::allocator const &)"
 ([email protected]@[email protected]@[email protected]@@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char * __thiscall std::allocator::allocate(unsigned int)"
 ([email protected][email protected]@[email protected]@[email protected]) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::allocator::max_size(void)const "
 ([email protected][email protected]@[email protected]@QBEIXZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(char const *)"
 ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::assign(char const *,unsigned int)"
 ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "protected: char * __thiscall std::basic_string,class std::allocator >::_Myptr(void)"
 ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@IAEPADXZ) already defined in libalglib.lib(trfac.obj)
1>   Creating library Debuginterpolating-scheme.lib and object Debuginterpolating-scheme.exp
1>Debuginterpolationg-scheme.exe : fatal error LNK1169: one or more multiply defined symbols found

Thanks for any HELP!

This is more of a conflict between alglib and the STL.Alglib uses the STL string and when linking  it to part of your code which uses string then it will find another set of objects for string and come up with a problem.If you are sure that alglib was built using the same version of the compiler that you are using then there is a way around it, but I’m hesitant because it can cause problems. But the thing you can try is to set the linker to allow multiply defined  symbols. You can set this by going to Project Properties->Configuration Properties->Linker->Command Line and in the Additional Options box type /FORCE:MULTIPLE.This isn’t something I recommend though, so do testing to make sure that it works fine.

Thanks for answer, with this option, project compile, link and run, but it doesn work 🙁 Any other advice? Alglib was compile by Visual Studio 2008 Command Prompt and my project is compiling via F5 in VS 2008 EE. But it is strange, that when i disable the use of ITK, aleglib normally works and there are no errors…

You can wrap the lib in a dll  and use it in your exe via a C or COM interface