Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am building a project in which 1 other project is also included. My both projects are built with "Use MFC in a Static Library" and "MT" options. My second project is a library which is compiled successfully but when i compile my main project i get following errors:
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin.h(3343): error C2872: 'CString' : ambiguous symbol

Can anybody tell me the real cause of this error


I am trying to reorder the includes and using namespaces but getting no success.
Somewhere in library code i have defined CString (typedef CObjectSimple<pstring> CString in header file A which is included in header file B. I have included header file B in my app

C#
#pragma once
#include "stdafx.h"
#include "PDFTools.h"

#include <sstream>
#include <myheaderfiles>
#include <myheaderfiles>           //This is header file which is giving error and which include the header file where CString is typedef.
#include <myheaderfiles>
#include <myheaderfiles>
#include <myheaderfiles>
#include <myheaderfiles>
#include <myheaderfiles>
#include <boost/program_options.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <limits>
#include <myheaderfiles>
#include <myheaderfiles>

#ifdef WIN32
#include <Windows.h>
#undef max
#undef min
#endif

using namespace std;
using namespace boost;

using namespace ...;     This is namespace which is getting error
using namespace ...;
namespace ...;


I commented the win32 include but got no success.

Error is given by system file as u can see
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin.h(3331): error C2872: 'CString' : ambiguous symbol
could be 'C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxstr.h(99) : ATL::CStringT<BaseType,StringTraits> CString'
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL<wchar_t>
]
or .....myheaderFilelocation(295) : myclassobject::CString'
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin.h(3361) : see reference to function template instantiation 'TReturnType CWnd::EnlargeBufferGetText<TReturnType,int>(TRetur nType,LPTSTR &,TCchType &,TCchType,TCchType,UINT,WPARAM &,LPARAM &,CString &) throw(...) const' being compiled
with
[
TReturnType=BOOL,
TCchType=int
]
C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin4.inl(132) : see reference to function template instantiation 'TReturnType CWnd::EnlargeBufferGetText<BOOL>(TReturnType,LPTST R &,int &,UINT,WPARAM &,LPARAM &,CString &) throw(...) const' being compiled
with
[
TReturnType=BOOL
]


one thing which i forget to tell is that this code is working fine in Debug mode. Release mode is giving problem
Posted
Comments
Richard MacCutchan 7-Oct-10 7:26am    
You have 9 includes of <myheaderfiles>- surely some mistake!

Why do you have this in your code NINE TIMES?

#include <myheaderfiles>


Also, does myheaderfiles.h also have this line:

#include "stdafx.h"
 
Share this answer
 
Comments
Ravikant 7-Oct-10 7:58am    
Actually they are totaly different header files. I just replaced all those with "myheaderFiles".

All those header files are of Library and they does not contain
#include "stdafx.h"
It looks like you're including the MFC CString definition and then typedefing it as something else. I'm sort of surprised the typedef doesn't give you a redefinition error but that what it looks like from what you've said.

Cheers,

Ash
 
Share this answer
 
Comments
Ravikant 7-Oct-10 8:05am    
Actually i have typedef'd CString in library where i havn't included support for MFC. But in my main project I am using "Use MFC in a Static Library" That's why error is coming

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900