[ASIO|Thread] Advice for removing MFC/ afxwin.h dependancies

Hi all, I've inherited a windows C++ application which I've extended and that I'm now preparing for porting to Linux. I'm going through the app removing any MFC code replacing it with standard C++. I use Boost asio and thread and they seem to be requiring me to include afxwin.h before any boost includes or it won't build complaining that Winsock.h or Windows.h has alreday been included. I can bodge around those errors, but then the code doesn't link as new and delete have already been referenced from an afx lib. Is there any general advice for Boost/MFC coexistance or MFC removal? Thanks, Simon ++++ IMPORTANT NOTICE ++++ This email may contain confidential information and will be protected by copyright. It is intended only for the use of the person(s) to whom it is addressed and any unauthorised use (including forwarding or dissemination the contents) may be unlawful. If you receive this email by mistake, please advise the sender immediately by using the reply facility on your email software and delete the email from your computer. Opinions, conclusions and other information in this email that do not relate to the official business of this organisation shall be understood as neither given nor endorsed by it. If this message forms part of a quotation for the supply of goods, the quotation is an invitation to treat only. No contract will come into effect until the Company issuing such quotation issues an acknowledgment of order for the supply of such goods. The contract will be on the terms of such acknowledgment of order. ------------------------------------------------------------------------ Teledyne Defence Limited phone: +44 (0) 1274 531602 web: www.teledynedefence.co.uk ------------------------------------------------------------------------

I can bodge around those errors, but then the code doesn't link as new and delete have already been referenced from an afx lib.
Could you copy&paste the linker errors? Make sure that your MFC and CRT (both in the app and in boost) linkage are coherent. With just two afxwin.h inclusions the linker error is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in
boost-users-bounces@lists.boost.org wrote on 25/05/2010 17:52:09: libcpmtd.lib(newaop.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj) I'm using /NODEFAULTLIB:libcmt.lib Simon ++++ IMPORTANT NOTICE ++++ This email may contain confidential information and will be protected by copyright. It is intended only for the use of the person(s) to whom it is addressed and any unauthorised use (including forwarding or dissemination the contents) may be unlawful. If you receive this email by mistake, please advise the sender immediately by using the reply facility on your email software and delete the email from your computer. Opinions, conclusions and other information in this email that do not relate to the official business of this organisation shall be understood as neither given nor endorsed by it. If this message forms part of a quotation for the supply of goods, the quotation is an invitation to treat only. No contract will come into effect until the Company issuing such quotation issues an acknowledgment of order for the supply of such goods. The contract will be on the terms of such acknowledgment of order. ------------------------------------------------------------------------ Teledyne Defence Limited phone: +44 (0) 1274 531602 web: www.teledynedefence.co.uk ------------------------------------------------------------------------

With just two afxwin.h inclusions the linker error is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
I'm using /NODEFAULTLIB:libcmt.lib
Does the following link help: http://support.microsoft.com/kb/148652

boost-users-bounces@lists.boost.org wrote on 26/05/2010 12:39:24:
With just two afxwin.h inclusions the linker error is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
I'm using /NODEFAULTLIB:libcmt.lib
Does the following link help: http://support.microsoft.com/kb/148652
I've been doing some trial and error with /NODEFAULTLIB as suggest by MS with not a vast amount of sucess. I build using a makefile. If I exclude libcmt.lib I get the new and delete problems shown above. If I exclude nafxcwd.lib several of my objects have an unresolved external of __afxForceEXCLUDE My suspicion is moving away from boost and toward the Cypress USB library. I didn't expect device drivers to use MFC. If I explicitly include nafxcwd.lib in my library list, it links sucessfully. :-( Simon ++++ IMPORTANT NOTICE ++++ This email may contain confidential information and will be protected by copyright. It is intended only for the use of the person(s) to whom it is addressed and any unauthorised use (including forwarding or dissemination the contents) may be unlawful. If you receive this email by mistake, please advise the sender immediately by using the reply facility on your email software and delete the email from your computer. Opinions, conclusions and other information in this email that do not relate to the official business of this organisation shall be understood as neither given nor endorsed by it. If this message forms part of a quotation for the supply of goods, the quotation is an invitation to treat only. No contract will come into effect until the Company issuing such quotation issues an acknowledgment of order for the supply of such goods. The contract will be on the terms of such acknowledgment of order. ------------------------------------------------------------------------ Teledyne Defence Limited phone: +44 (0) 1274 531602 web: www.teledynedefence.co.uk ------------------------------------------------------------------------

boost-users-bounces@lists.boost.org wrote on 26/05/2010 12:39:24:
With just two afxwin.h inclusions the linker error is: nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj) nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
I'm using /NODEFAULTLIB:libcmt.lib
Does the following link help: http://support.microsoft.com/kb/148652
Now I'm trying to get the release build linking. The same options as before, but using non d libs. The first linker error is a boost one: libboost_system-vc90-mt-s-1_43.lib(error_code.obj) : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) I'm building with /EHsc. Exception handling is missing? Simon ++++ IMPORTANT NOTICE ++++ This email may contain confidential information and will be protected by copyright. It is intended only for the use of the person(s) to whom it is addressed and any unauthorised use (including forwarding or dissemination the contents) may be unlawful. If you receive this email by mistake, please advise the sender immediately by using the reply facility on your email software and delete the email from your computer. Opinions, conclusions and other information in this email that do not relate to the official business of this organisation shall be understood as neither given nor endorsed by it. If this message forms part of a quotation for the supply of goods, the quotation is an invitation to treat only. No contract will come into effect until the Company issuing such quotation issues an acknowledgment of order for the supply of such goods. The contract will be on the terms of such acknowledgment of order. ------------------------------------------------------------------------ Teledyne Defence Limited phone: +44 (0) 1274 531602 web: www.teledynedefence.co.uk ------------------------------------------------------------------------

Now I'm trying to get the release build linking. The same options as before, but using non d libs. The first linker error is a boost one: libboost_system-vc90-mt-s-1_43.lib(error_code.obj) : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z)
I'm building with /EHsc. Exception handling is missing?
Ensure you link the std library (libcpmt.lib), and that it's of the correct version (if you've got several versions installed). Particularly, check the path, which is used for libs. The same static libs should be used by boost.

boost-users-bounces@lists.boost.org wrote on 26/05/2010 13:45:29:
Ensure you link the std library (libcpmt.lib), and that it's of the correct version (if you've got several versions installed). Particularly, check the path, which is used for libs. The same static libs should be used by boost. Strangely the release and Debug builds require different settings. I had to remove /NODEFAULTLIB:libcmt.lib for the Release to build.
Thanks for your help. I have the feeling this will bite me again soon though. Simon ++++ IMPORTANT NOTICE ++++ This email may contain confidential information and will be protected by copyright. It is intended only for the use of the person(s) to whom it is addressed and any unauthorised use (including forwarding or dissemination the contents) may be unlawful. If you receive this email by mistake, please advise the sender immediately by using the reply facility on your email software and delete the email from your computer. Opinions, conclusions and other information in this email that do not relate to the official business of this organisation shall be understood as neither given nor endorsed by it. If this message forms part of a quotation for the supply of goods, the quotation is an invitation to treat only. No contract will come into effect until the Company issuing such quotation issues an acknowledgment of order for the supply of such goods. The contract will be on the terms of such acknowledgment of order. ------------------------------------------------------------------------ Teledyne Defence Limited phone: +44 (0) 1274 531602 web: www.teledynedefence.co.uk ------------------------------------------------------------------------

Strangely the release and Debug builds require different settings. I had to remove /NODEFAULTLIB:libcmt.lib for the Release to build.
Well, if you wanted symmetric settings you had to change it to /NODEFAULTLIB:libcmtD.lib :)

smbrown@teledyne.com wrote:
Hi all,
I've inherited a windows C++ application which I've extended and that I'm now preparing for porting to Linux.
I'm going through the app removing any MFC code replacing it with standard C++. I use Boost asio and thread and they seem to be requiring me to include afxwin.h before any boost includes or it won't build complaining that Winsock.h or Windows.h has alreday been included.
I can bodge around those errors, but then the code doesn't link as new and delete have already been referenced from an afx lib.
Is there any general advice for Boost/MFC coexistance or MFC removal?
FYI, I'm using both boost::asio and boost::thread across mac and windows portably and without a need to explicitly include windows headers. Jeff
participants (3)
-
Igor R
-
Jeff Flinn
-
smbrown@teledyne.com