I've recently been tasked at work to try to migrate a C++ project from its old Windws 2003 server to a Windows 2008. For the moment, I am trying to build the application locally, on my Windows 7PC. I've followed an installation guide that I've received. Things seem to have worked quite well. The problem that I'm having is that, after the compilation step, the linker is giving me the following error:
msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z) already defined in CellSortTypeIds.obj
This is run in the debug mode, by the way. In the release mode, I am getting the same error. I can show you the corresponding CPP file:
CellSortTypeIds.h file:
#ifndef CELL_SORT_TYPE_IDS_H #define CELL_SORT_TYPE_IDS_H #include <iostream> #include <QtCore/QString> namespace CellSortTypeIds { enum CellSortTypeEnum { NAME=0, LAC, CI, NB_ITEMS }; static const QString mStrings[] = { QT_TR_NOOP("Tri par code Nom"), QT_TR_NOOP("Tri par code LAC"), QT_TR_NOOP("Tri par code CI") }; QString getQString(const CellSortTypeIds::CellSortTypeEnum aCellSortType); CellSortTypeEnum getCellSortTypeFromQString( QString aCellSortType ); } std::ostream& operator <<(std::ostream &, const CellSortTypeIds::CellSortTypeEnum&); #endif //CELL_SORT_TYPE_IDS_H
CellSortTypeIds.cpp file
#include "CellSortTypeIds.h" #include <QtCore/QObject> using namespace std; ostream& operator <<(ostream &out, const CellSortTypeIds::CellSortTypeEnum& aCellSortType) { out << CellSortTypeIds::getQString(aCellSortType).toAscii().operator const char*(); return out; } QString CellSortTypeIds::getQString(const CellSortTypeIds::CellSortTypeEnum aCellSortType) { QString result(""); if( aCellSortType < CellSortTypeIds::NB_ITEMS ) { result = QObject::tr( CellSortTypeIds::mStrings[aCellSortType].toAscii().data() ); } else { cerr << __FILE__<< "(" <<__LINE__ << "): mStrings[" << (int)aCellSortType << "] not initialised" << endl; } return result; } CellSortTypeIds::CellSortTypeEnum CellSortTypeIds::getCellSortTypeFromQString( QString aCellSortTypeString ) { CellSortTypeIds::CellSortTypeEnum theEnum( CellSortTypeIds::NAME ); bool found( false ); for( int index( 0) ; index < CellSortTypeIds::NB_ITEMS && !found ; index++ ) { if( QObject::tr(CellSortTypeIds::mStrings[ index ].toAscii().data()) == aCellSortTypeString ) { theEnum = (CellSortTypeIds::CellSortTypeEnum)index; found = true; } } return theEnum; }
My C++ knowledge is not that good. I've read several posts on SO regarding this issue, some telling about the configured runtime, some about not defining operators in the header files, but putting them in the cpp file. Here I believe it is not the case.
My suspicion is that there's an issue in these two files that I can't figure out. Any idea is appreciated. Let me know if you need any more details. Thank you in advance, and please don't hesitate to give any feedback on the structure of the question, since it is my first question, after all.