I added a new workspace called Token to my project. It uses the STL library. I made this workspace a Win32 static library. So my main Workspace (Win32 Application can use this library). I have no problem compling this Token (static library). I added this library to link settings and its header files to my main Workspace.
When I rebuild my main Workspace. I get a whole bunch of link errors.
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2005: "class CWinThread * __stdcall AfxBeginThread(unsigned int (__cdecl*)(void *),void *,int,unsigned int,unsigned long,struct _SECURITY_ATTRIBUTES *)" (?AfxBeginThread@@YGPAVCWinThread@@P6AIPAX@Z0HIKPAU_SECURIT
Y_ATTRIBUTES@@@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual void __thiscall CWinThread::Delete(void)" (?Delete@CWinThread@@UAEXXZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual int __thiscall CWinThread::IsIdleMessage(struct tagMSG *)" (?IsIdleMessage@CWinThread@@UAEHPAUtagMSG@@@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual int __thiscall CWinThread::PreTranslateMessage(struct tagMSG *)" (?PreTranslateMessage@CWinThread@@UAEHPAUtagMSG@@@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual int __thiscall CWinThread::ProcessMessageFilter(int,struct tagMSG *)" (?ProcessMessageFilter@CWinThread@@UAEHHPAUtagMSG@@@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual class CWnd * __thiscall CWinThread::GetMainWnd(void)" (?GetMainWnd@CWinThread@@UAEPAVCWnd@@XZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(thrdcore.obj) : error LNK2005: "public: virtual int __thiscall CWinThread::PumpMessage(void)" (?PumpMessage@CWinThread@@UAEHXZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(afxinl1.obj) : error LNK2005: "protected: __thiscall CObject::CObject(void)" (??0CObject@@IAE@XZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(afxinl1.obj) : error LNK2005: "public: virtual __thiscall CObject::~CObject(void)" (??1CObject@@UAE@XZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(afxinl1.obj) : error LNK2005: "public: virtual void __thiscall CObject::Serialize(class CArchive &)" (?Serialize@CObject@@UAEXAAVCArchive@@@Z) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(afxinl1.obj) : error LNK2005: "public: __thiscall CString::CString(void)" (??0CString@@QAE@XZ) already defined in mfc42d.lib(MFC42D.DLL)
nafxcwd.lib(afxinl1.obj) : error LNK2005: "public: int __thiscall CString::IsEmpty(void)const "
and more…..
I not that famillar with STL programming, incorporating into non STL code
Here is my STL workspace called Token (no problem compliing this)
#include "ETokenFile.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Basically I want to call this library from my main workspace App class Initinstance function
// when I put this line I get the link errors
CETokenFile TFile;
Bore
June 8th, 2001, 02:15 PM
It looks to me that you're linking both nafxcwd.lib and mfc42d.lib into your project. Don't you need to take one of them out?
Jim Mcpherson
June 8th, 2001, 02:48 PM
My main workspace that is calling this library is a non STL workspace.
gus8971
June 8th, 2001, 03:20 PM
You are probably using two different CRT's for your library and your app.
Jim Mcpherson
June 8th, 2001, 04:10 PM
How do I get around it!!
Bore
June 8th, 2001, 04:14 PM
I don't understand your point. I don't think you're having an STL-related problem. The problem seems to be that you have created a library that links in nafxcwd.lib (or whatever the name is) and you're linking that library in with your app, which is linking in mfc42d.lib, and you're getting name conflicts. You only need one of those libraries.
Paul McKenzie
June 8th, 2001, 05:53 PM
There is no such thing as a "non-STL workspace". STL is just a bunch of header files. It has nothing to do with the link process.
Regards,
Paul McKenzie
Paul McKenzie
June 8th, 2001, 06:04 PM
STL is a set of templates and is part of the standard C++ library. It has absolutely nothing to do with linking. You #include the header file, and the header file has *the entire code* within it since it is made up of entirely *templates*. Therefore there is no need for a special library to be linked in for STL to work. Everything is taken care of at compile time.
Are you saying that if you eliminated the #includes of all of the STL headers, things are OK? If you look at your error messaeges, none of them even suggests anything to do with STL. If anything, you shouldn't be mixing stdafx.h with <windows.h>. Remove the precompiled headers and the stdafx.h and see if this problem goes away.
Regards,
Paul McKenzie
Jim Mcpherson
June 10th, 2001, 11:28 AM
I appreciate your response..
I tried get rid of the Precomplied header and the stdafx.h file. It did not help.
My main project where this (STL type class is called from) is an MFC AppWizard exe workspace with no document/view support (non STL, uses CString .....). I calling this class (CETokenFile eTFile) from my app class Initinstance function.
[/ccode]
// The CETokenFile class
// header
#ifndef _ETOKENFILE_H
#define _ETOKENFILE_H
class CETokenFile
{
public:
CETokenFile();
~CETokenFile();
void GetIDKey();
};
#endif
// Cpp file
#include "ETokenFile.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows //headers
#pragma warning(disable: 4786) // long debug info
CETokenFile::~CETokenFile()
{
}
// This function is bigger but took out most for debugging this problem
void CETokenFile::GetIDKey()
{
long error = 0;
string password;
int rv = 0;
Linking...
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
etokenfile.obj : error LNK2001: unresolved external symbol "public: __thiscall RMReconnectableApduTalker::RMReconnectableApduTalker(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long)" (??0R
MReconnectableApduTalker@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@K@Z)
etokenfile.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall RMApduTalker::~RMApduTalker(void)" (??1RMApduTalker@@UAE@XZ)
Debug/DdmTerm.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
DdmTerm.exe - 3 error(s), 1 warning(s)
My problem has to do with the (vendor's) AKS and Core include header files of this file. I am trying to implement a vendor's (eToken) code into my code. If I comment out these include files and the GetIDKey function it complies. Their code uses STL. It opens all the header files correctly.
I just do know how to correctly implement this. I not really famillar with STL.
Paul McKenzie
June 10th, 2001, 10:56 PM
Take a good look at the error messages. They may be long, but they are easily understood.
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
etokenfile.obj : error LNK2001: unresolved external symbol "public: __thiscall RMReconnectableApduTalker::RMReconnectableApduTalker(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long)" (??0R
MReconnectableApduTalker@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@K@Z)
This means you defined a constructor for class RMReconnectableApduTalker that takes a reference to a std::string and an unsigned long, but there is no implementation of this constructor anywhere in your program.
This means you defined a destructor for class RMApduTalker, but there is no implementation of the destructor.
Also, include the STL headers first before including any other header.
Regards,
Paul McKenzie
Jim Mcpherson
June 11th, 2001, 08:58 AM
Your previous reply help me a liitle bit. I forgot to include the vendors library (apdulib) in the linking.
But I getting these errors in the linking:
Generating Code...
Linking...
msvcprtd.lib(MSVCP60D.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_strin
g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in apdulib.lib(rm_apdutalker.obj)
msvcprtd.lib(MSVCP60D.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> >(char const *,class basic_
string<char,struct std::char_traits<char>,class std::allocator<char> >::allocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z) already defined in apdulib.lib(rm_apdutalker.obj)
msvcprtd.lib(MSVCP60D.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 basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> >::allocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV?$allocator@D@1@@Z) already defined in apdulib.lib(rm_apdutalker.obj)
libcpmtd.lib(ios.obj) : error LNK2005: "public: void __thiscall std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QAEXH_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "public: virtual __thiscall std::ios_base::~ios_base(void)" (??1ios_base@std@@UAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "protected: void __thiscall std::ios_base::_Addstd(void)" (?_Addstd@ios_base@std@@IAEXXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "protected: void __thiscall std::ios_base::_Init(void)" (?_Init@ios_base@std@@IAEXXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale0.obj) : error LNK2005: "public: class std::locale::facet const * __thiscall std::locale::_Getfacet(unsigned int,bool)const " (?_Getfacet@locale@std@@QBEPBVfacet@12@I_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale0.obj) : error LNK2005: "public: bool __thiscall std::locale::_Iscloc(void)const " (?_Iscloc@locale@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _calloc already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _realloc already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _free already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtIsValidHeapPointer already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(lconv.obj) : error LNK2005: _localeconv already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(tolower.obj) : error LNK2005: _tolower already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __ltoa already defined in LIBCMTD.lib(xtoa.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBCMTD.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCD" conflicts with use of other libs; use /NODEFAULTLIB:library
apdulib.lib(rm_apdutalker.obj) : error LNK2001: unresolved external symbol "class std::basic_ofstream<char,struct std::char_traits<char> > __log" (?__log@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A)
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/DdmTerm.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
DdmTerm.exe - 29 error(s), 3 warning(s)
I am not doing much in the code. I am just try to link it. I am getting library conflicts.
Paul McKenzie
June 11th, 2001, 01:32 PM
What compiler was used to compile the vendor's library? Is it a static library or an import library? If it is, a static library, then you better make sure that:
a) The vendor used the same brand / version of compiler you're using now to compile the library.
b) You are using *exactly* the same run-time settings that the vendor built his library with.
A static library must match everything that your current project is using. Project settings, run-time library used, everything. All of the errors that I see here indicate that the vendor used a different run-time setting when they built their library, and you have used different run-time settings for your program. For example, the vendor may have used the "MultiThreaded DLL" setting, and you may be using just the "Single Thread".
If it is an import library instead of a static library, then you still must match the run-time settings.
Also, the last error is very suspicious:
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Is this a console app? Why is "main" undefined? This function should never be undefined.
Again, contact the vendor and make sure that you are using the settings that they used to build the library. Adding a static library (assuming it is a static library) relies a lot more care than just adding the file to your project.
Regards,
Paul McKenzie
Jim Mcpherson
June 11th, 2001, 01:47 PM
Paul you probably right about the vendor's library. I changed it. Instead using a static library. I made a class inside the my main workspace for it (MFC AppWizard, no document/view architecture) and added their library calls to my linker. I contacted the vendor and their looking into it. Because if I comment 1 line (test code) which calls one of there modules it compiles and links properly.
//#include "stdafx.h"
#include "ETokenFile.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#pragma warning(disable: 4786) // long debug info
void CETokenFile::GetIDKey()
{
long error = 0;
string password;
int rv = 0;
// if I comment this line out it complies
RMReconnectableApduTalker t("AKS ifdh 0", SCARD_SHARE_SHARED);
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.