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<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)"
 (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator=(char const *)"
 (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)"
 (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::size(void)const "
 (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)"
 (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)"
 (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator<char>::allocator<char>(void)"
 (??0?$allocator@D@std@@QAE@XZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::allocator<char>::deallocate(char *,unsigned int)"
 (?deallocate@?$allocator@D@std@@QAEXPADI@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __thiscall std::allocator<char>::allocator<char>(class std::allocator<char> const &)"
 (??0?$allocator@D@std@@QAE@ABV01@@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char * __thiscall std::allocator<char>::allocate(unsigned int)"
 (?allocate@?$allocator@D@std@@QAEPADI@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: unsigned int __thiscall std::allocator<char>::max_size(void)const "
 (?max_size@?$allocator@D@std@@QBEIXZ) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(char const *)"
 (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBD@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(char const *,unsigned int)"
 (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z) already defined in libalglib.lib(trfac.obj)
1>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "protected: char * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Myptr(void)"
 (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAEPADXZ) already defined in libalglib.lib(trfac.obj)
1>   Creating library Debug\interpolating-scheme.lib and object Debug\interpolating-scheme.exp
1>Debug\interpolationg-scheme.exe : fatal error LNK1169: one or more multiply defined symbols found

Thanks for any HELP!

Are your headers vendor-supplied or self-written? Due to the multiple declaration issue, I'm wondering if they're not properly guarded.

Either that, or a couple of the errors make it look like there is an issue with namespaces. I see a couple errors that seem to be mentioning std::allocator(s) as a problem.

I'm afraid I can't help much beyond that though.

Thanks for reply!

Header files, which i include to my project, were provided with Alglib and ITK, so they are not self-made. I have only one header file with declaration of my one class.

I see it as well, that there could be some problem with namespace, any advice how to solve this?

Unfortunately, I do not know enough about namespaces to be of much help on that subject.

Maybe someone else can help better now that there is some direction to start heading down.

Let's doublecheck for header guards quick. If you open your headers, do you see lines similar to either of these?

//option 1, pragma:
#pragma once

//or, option 2, macros
#ifndef HEADER_NAME
#define HEADER_NAME

/* ... code here ... */

//#endif

Edited 6 Years Ago by Fbody: n/a

At a glance it looks as if the .dll is being included twice possibly under different names

as all the errors come from MSVCP90D.dll I am not sure how best to stop it though...

Thanks for reply!

Header files, which i include to my project, were provided with Alglib and ITK, so they are not self-made. I have only one header file with declaration of my one class.

I see it as well, that there could be some problem with namespace, any advice how to solve this?

If I open one, only mine, header, I dont have this:

option 2, macros
#
#ifndef HEADER_NAME
#
#define HEADER_NAME

I have there only include.

If i open headers provided with ITK or Alglib, there is ifndef, define...

How are you currently linking to both libraries?

Project settings etc...

If I open one, only mine, header,

This last statement is a bit confusing are you saying you have source code for alglib, itk ?

I have downloaded source code for both ITK and Alglib. Then I have followed the instructions for compiling it.
ITK - I have created a project for VS via Cmake, which configured all project properites for using ITK toolkit. Then I added in project (via add new item) library for Alglib - libalglib.lib. In tools I added in VC directories location of include files for all .h files, which alglib uses (these, which I created while compiling Alglib via user manual included in folder with Alglib).

I hope, I described it sufficiently.

I tried to change ITK, in hope, that ALGLIB will work with another library and oops, I used GDCM library (for reading dicoms) and there it is - same errors with libalglib.lib as with the ITK ;(

This article has been dead for over six months. Start a new discussion instead.