There's obviously something wrong with my build, but I can't figure it out. I narrowed this down to one of my projects: first build after clean fails, all following builds succeed.
I get linking errors which say that some symbols are already defined:
>------ Build started: Project: Problem, Configuration: Debug Win32 ------ > Blah blah blah... 23> Creating library D:\SVN.DRA.WorkingCopy\Debug\Problem.lib and object D:\SVN.DRA.WorkingCopy\Debug\Problem.exp 23>ProblemDependency1.lib(PD1.obj) : error LNK2005: "public: unsigned short __thiscall PD2Class::getFoo(void)const " (?getFoo@PD2Class@@QBEGXZ) already defined in ProblemDependecy2.lib(ProblemDependency2.dll) 23>ProblemDependency1.lib(PD1.obj) : error LNK2005: "public: void __thiscall PD2Class2::`default constructor closure'(void)" (??_FPD2Class2@Image@DRA@@QAEXXZ) already defined in ProblemDependency2.lib(ProblemDependency2.dll) 23>D:\SVN.DRA.WorkingCopy\Debug\Problem.dll : fatal error LNK1169: one or more multiply defined symbols found - Problem is a C++/CLI project, built with the /clr switch, which references the unmanaged C++ projects ProblemDependency1, a static lib, and ProblemDependency2, a dll.
- ProblemDependency1 references ProblemDependency2.
- getFoo() is declared as inline and defined outside of the class declaration, in the .h
- PD2Class2 doesn't have an explicitly defined default constructor, but it has a constructor which has all default arguments, so you could say it includes the default constructor as a special case
- The .h's where these are defined have #pragma once as their first line.
Any hint on troubleshooting this? I can post more info if needed
Update: I solved the first error thanks to Anders Abel's suggestion, but I still can't solve the second one (the one about the default constructor)
Update: If I compile using MSBuild outside Visual Studio, it fails always, with the same error
Edit: Here's some code. First, a bit of PD2Class2's declaration. PD2Class2's real name is CImage (feeling lazy to anonymize), CImage.h:
#pragma once #pragma warning( disable: 4251 ) //TODO: Disable and solve #include "ImageProperties.h" #include "../CommonCppLibrary/CriticalSection.h" #include <windows.h> #include <stdexcept> #include <string> class CSharedMemory; class EmptyImageException; struct IShape; struct SImageStatics { unsigned short low3Percentile; unsigned short high97Percentile; unsigned short medianPixelValue; unsigned short meanPixelValue; unsigned short minPixelValue; unsigned short maxPixelValue; }; namespace DRA{ namespace Image{ class __declspec(dllexport) CImage { friend class CImageLock; //Attributes int m_iPitch; protected: mutable CImageProperties m_cProperties; CSharedMemory * m_pSharedMemmory; mutable DRA::CommonCpp::CCriticalSection m_csData; static const float PIXEL_FREQUENCY_COVERAGE; static const float PIXEL_CUTOFF_PERCENTAGE; static const int MINIMUM_PIXEL_FREQUENCY; //Pixels with a frequency lower than this are ignored static const int MINIMUM_WINDOW_WIDTH_FOR_16_BITS; //Methods //Some private methods public: CImage( DWORD dwWidth = 0, DWORD dwHeight = 0, ULONG uBytesPerPixel = 0, bool isSigned = false, EPhotometricInterpretation ePI = PI_UNKNOWN, UINT bitsStored = 0, float pw = -1.0f, float ph = -1.0f, BYTE * pData = NULL ); CImage( const CImageProperties& cProperties, int iPitch = 0 ); CImage( const CImage& rImage ); virtual ~CImage(); virtual CImage& operator=( const CImage& ); bool operator==( const CImage& rImage ); //Alter State //More methods //Query State //More methods }; } } Next, the constructor's definition, from CImage.cpp:
CImage::CImage( DWORD dwWidth, DWORD dwHeight, ULONG uBytesPerPixel, bool isSigned, EPhotometricInterpretation ePI, UINT bitsStored, float pw, float ph, BYTE * pData ) : m_iPitch( dwWidth * uBytesPerPixel ), m_cProperties( dwWidth, dwHeight, uBytesPerPixel, bitsStored, ePI, isSigned, pw, ph ), m_pSharedMemmory( NULL ), m_csData(){ m_pSharedMemmory = new CSharedMemory( pData ? pData : new BYTE[getSize()] ); }
PD2Class2(you can strip the rest of the class to shorten the code). Also please include any macros used in the class / constructor declaration.