Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using static libraby in MFC

I try to use a static library in my MFC project but I get the following linker error:

1>------ Build started: Project: Csetkliens, Configuration: Debug Win32 ------
1>Build started 2012.05.20. 16:12:49.
1>InitializeBuildStatus:
1>  Touching "Debug\Csetkliens.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>  All outputs are up-to-date.
1>ResourceCompile:
1>  All outputs are up-to-date.
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ) already defined in Csetkliens.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in Csetkliens.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in Csetkliens.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: struct std::_Iterator_base12 * * __thiscall std::_Container_base12::_Getpfirst(void)const " (?_Getpfirst@_Container_base12@std@@QBEPAPAU_Iterator_base12@2@XZ) already defined in Csetkliens.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmtd.lib(xthrow.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __invalid_parameter already defined in libcmtd.lib(invarg.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __CrtDbgReportW already defined in libcmtd.lib(dbgrptw.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in libcmtd.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in libcmtd.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in libcmtd.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memmove already defined in libcmtd.lib(memmove.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _malloc already defined in libcmtd.lib(dbgmalloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _realloc already defined in libcmtd.lib(dbgrealloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fflush already defined in libcmtd.lib(fflush.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: ___iob_func already defined in libcmtd.lib(_file.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in libcmtd.lib(dbgfree.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _floor already defined in libcmtd.lib(_floor_pentium4_.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _ldexp already defined in libcmtd.lib(_ldexp_.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _abort already defined in libcmtd.lib(abort.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _isspace already defined in libcmtd.lib(_ctype.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>D:\Projektek\V.felev\Felulettervezes (MFC) - Halozatok\Csetkliens\Debug\Csetkliens.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The name of the static library is kriptolib.lib it is my own product. It doesn't use any MFC. I can't figure out what is the problem.

The problem occurs when I try to make a new object from the kriptolib.

theApp.encryption = new RC4();

If I comment the line below the compiler doesn't show any errors.

like image 337
Forro Istvan Avatar asked May 20 '12 13:05

Forro Istvan


People also ask

Is MFC obsolete?

No, it's not "deprecated".

What is use of static library?

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

Is MFC still popular?

Microsoft Foundation Class Library (MFC) is a C++ object-oriented library for developing desktop applications for Windows. MFC was introduced by Microsoft in 1992 and quickly gained widespread use. While Microsoft has introduced alternative application frameworks since then, MFC remains widely used.

Where do I put my static library?

Static libraries belong next to their corresponding dynamic libraries, and in accordance with the FHS. Keep in mind that static libraries are usually only needed to build software, not run it.


1 Answers

you need change the testing project to use MTd(Multi-threaded Debug).

From the Property Pages select Configuration Properties ==> C/C++ ==> Code Generation ==> Runtime Library ==> Multi-threaded Debug (/MTd).

like image 146
bystander Avatar answered Oct 17 '22 08:10

bystander