3. The symbol is defined differently in two member objects in different libraries, and both member objects were used.
4. An absolute is defined twice, with a different value in each definition.
5. A header file declared and defined a variable. Possible solutions include:
· Declare the variable in .h: extern BOOL MyBool; and then assign to it in a .c or .cpp file: BOOL MyBool = FALSE;.
· Declare the variable static.
· Declare the variable selectany.
6. If you use uuid.lib in combination with other .lib files that define GUIDs (for example, oledb.lib and adsiid.lib).
7. To fix, add /FORCE:MULTIPLE to the linker command line options, and make sure that uuid.lib is the first library referenced.
其中1,我一直说学习托管编程,但只是打雷。其实使用托管就是不使用C++的编译器,而是编译成
中间语言,这样可以充分利用.Net的庞大的类库,不熟悉不说,以后学习了可以补上。
其实遇到这个错误并不可怕,只要我们找出原因,知道为什么会引起这些错误后,就不难解决。根据自己平时的心得和MSDN的解释,主要有下面这些情况,可能引起lnk 2005错误。
A、 全局变量的重复定义,在实际的编程中我们应该尽量不使用全局变量。她会产生如下的错误:
AAA.obj error LNK2005 int book c?book@@3HA already defined in BBB.obj
其实这个错误很好找,book@@3HA这个就是你重复定义了的变量。至于是怎么重复定义,情况
很多。关键是要理解清楚变量的声明和定义,以及extern关键字的使用,这些是基础知识。
B、 文件的重复包含,因为头文件中会有很多的变量,函数声明,所以要是被重复无次序包含的话,就有可能产生lnk 2005错误。
解决方法是使用#ifndef #define #endif宏来预防头文件被多次包含时重复编译。或者使用#pragma once做预编译。
C、 库版本包含错误,这个里面分两种情况说下。
1、 第三方库引起错误,这个在做directshow程序的时候记忆尤为深刻。现在自己把那个库分别编译成了strmbasd.lib、strmbasd_Unicode.lib、strmbase.lib、strmbase_Unicode.lib,这样根据不同的版本和字符编码链接不同的库,就不会出现错误。这样问题没什么好多,自己注意就是。
2、 关于编译器编译选项设置引起的lnk 2005错误。如:
1>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __vsnwprintf_s already defined in LIBCMTD.lib(vswprnc.obj)
1>MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __vsnprintf_s already defined in LIBCMTD.lib(vsnprnc.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)
关于这个问题首先看http://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.71).aspx
我们应该搞清楚这些编译选项的区别和作用,它对我们编译程序有很好的作用。不然我很容易因
为编译选项选错而链接了错误的版本。关于编译选项所对应的链接库,可以参考msdn以下连接:
http://msdn.microsoft.com/en-us/library/abx4dbyh.aspx
C Run-Time Libraries (CRT)
C run-time library | Associated DLL | Characteristics | Option | Preprocessor directives |
libcmt.lib | None,static link. | Multithreaded, static link | _MT | |
msvcrt.lib | msvcr90.dll | Multithreaded, dynamic link (import library for MSVCR90.DLL). Be aware that if you use the Standard C++ Library, your program will need MSVCP90.DLL to run. | _MT, _DLL | |
libcmtd.lib | None,static link | Multithreaded, static link (debug) | /MTd | _DEBUG,_MT |
msvcrtd.lib | msvcr90d.dll | Multithreaded, dynamic link (import library for MSVCR90D.DLL) (debug). | /MDd | _DEBUG,_MT, _DLL |
msvcmrt.lib | msvcm90.dll | C Runtime import library. Used for mixed managed/native code. | /clr |
|
msvcurt.lib | msvcm90.dll | CRuntime importlibrary compiled as 100% pure MSIL code. All code complies with the ECMA URT spec for MSIL. | /clr:pure |
|
最后
这份《“java高分面试指南”-25分类227页1000+题50w+字解析》同样可分享给有需要的朋友,感兴趣的伙伴们可挑战一下自我,在不看答案解析的情况,测试测试自己的解题水平,这样也能达到事半功倍的效果!(好东西要大家一起看才香)
试自己的解题水平,这样也能达到事半功倍的效果!(好东西要大家一起看才香)
[外链图片转存中…(img-1HRowh18-1719188727929)]
[外链图片转存中…(img-b2NkvwAG-1719188727930)]