标签: lnk2005

错误LNK2005:已在LIBCMTD.lib中定义的new和delete(new.obj)

我有一个Visual Studio 2005解决方案,有两个项目.一个是静态库,另一个是用于测试静态库中的功能的可执行文件.静态库使用MFC.我构建解决方案时遇到以下错误.

uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??    3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj)
uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
Run Code Online (Sandbox Code Playgroud)

我不知道如何克服这一点.有人可以解释为什么会出现这个错误.任何给出概述.lib文件链接的解释都将受到高度赞赏.

c++ visual-studio-2005 lnk2005 visual-studio

33
推荐指数
6
解决办法
7万
查看次数

在使用Microsoft Visual Studio '08编译libpng时,如何避免"错误LNK2005:"(已经定义了stdlib函数)?

(为什么我要这样做:我没有运气在Windows上使用libpng预先构建的二进制文件(尽管经过了数小时的试验和错误),因此我现在正在尝试自己编译它.我发现这个有用的博客关于此的帖子,完成了Microsoft Visual Studio 2008项目文件,但遗憾的是仍然无法使用它.)

它在链接到此处找到的zlib二进制文件时成功编译,但在尝试将其链接到测试文件时,我收到以下内容:

    C:\Documents and Settings\Administrator\My Documents>cl "C:\Documents and Settin
    gs\Administrator\My Documents\test.c" "C:\Documents and Settings\Administrator\M
    y Documents\libpng.lib" -I "C:\Documents and Settings\Administrator\My Documents\include"

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.

    test.c
    Microsoft (R) Incremental Linker Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.

    /out:test.exe
    test.obj
    "C:\Documents and Settings\Administrator\My Documents\libpng.lib"
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMT.lib(
    abort.obj)
    MSVCRTD.lib(MSVCR90D.dll) : …

c lnk2005 visual-studio-2008 visual-studio visual-c++

16
推荐指数
1
解决办法
2万
查看次数

LNK2005(已定义)

我知道你已经看到21728517人在寻求这方面的帮助但是在搜索和阅读之后我真的无法想出这个.我知道这个错误,我以前见过它,但是,这一次,我似乎无法绕过它.

我也试过这个清单.

所以,错误:

Error   25  error LNK2005: "void __cdecl checkStatus(unsigned int &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (?checkStatus@@YAXAAIV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) already defined in DollarRecognizer.obj C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty

Error   26  error LNK2005: "void __cdecl depth2rgb(unsigned short const *,unsigned short *,char *,int,int)" (?depth2rgb@@YAXPBGPAGPADHH@Z) already defined in DollarRecognizer.obj  C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty

Error   27  error LNK2005: "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl explode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char)" (?explode@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@D@Z) already defined in DollarRecognizer.obj    C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty
Run Code Online (Sandbox Code Playgroud)

所以,问题是,这些是在"misc.h"中使用正确的#ifndef #define …

c++ lnk2005

12
推荐指数
1
解决办法
1万
查看次数

在C++中声明公共静态变量时链接错误

我有这个具有可变配置参数的类.我希望把它列入其他类:JugadorHumano,JugadorIA,Main,PartidaClasica,PartidaMision.

#pragma once

class Configuracion
{
public:
    static int MAX_ATAQUES;
    static int DIV_TERRITORIOS;
};

int Configuracion::MAX_ATAQUES = 5;
int Configuracion::DIV_TERRITORIOS = 3;
Run Code Online (Sandbox Code Playgroud)

我想要的是能够修改或读取其他类中的值.我不能声明一个静态变量并在声明中定义它.我不能让这些变量没有定义,因为我得到"Unresolved External"错误.

1>JugadorIA.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \
         (?MAX_ATAQUES@Configuracion@@2HA) already defined in JugadorHumano.obj
1>JugadorIA.obj : error LNK2005: "public: static int Configuracion::DIV_TERRITORIOS" \
         (?DIV_TERRITORIOS@Configuracion@@2HA) already defined in JugadorHumano.obj
1>Main.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \
         (?MAX_ATAQUES@Configuracion@@2HA) already defined in JugadorHumano.obj
1>Main.obj : error LNK2005: …
Run Code Online (Sandbox Code Playgroud)

c++ linker static lnk2005

9
推荐指数
1
解决办法
9684
查看次数

Visual Studio 2005中的LNK 2005错误

我在Windows XP上使用Visual Studio 2005.我正在尝试使用"Google Test"框架.但由于链接器错误,我无法进行一次测试.

我在调试模式下使用/ MDd选项构建了Google Test源文件,而不是我创建了新项目.然后将此链接中的步骤写入项目属性文件.

比我尝试使用/ MDd选项构建调试模式并发生以下错误.你能帮帮忙吗?谢谢.

 #include "gtest/gtest.h"
TEST(sample_test_case, sample_test)
{
    EXPECT_EQ(1, 1);
}

int main(int argc, char** argv) 
{ 
    return 1;
}


1>------ Build started: Project: try3, Configuration: Debug Win32 ------
1>Compiling...
1>try3.cpp
1>Linking...
1>libcpmtd.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP80D.dll)
1>libcpmtd.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP80D.dll)
1>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class …
Run Code Online (Sandbox Code Playgroud)

visual-studio-2005 linker-errors googletest lnk2005

7
推荐指数
1
解决办法
1万
查看次数

Visual Studio 2010中的Visual C++中的LNK 2005

我正在尝试编译在MS VS 2010中使用Visual C++ 2005和MFC编写的C++程序.遗憾的是,我在编译期间遇到以下错误:

Error 2 error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) already defined in CMemDCImpl.obj Project\Project\Project\uafxcwd.lib(afxglobals.obj) Project.
Run Code Online (Sandbox Code Playgroud)

CMemDCImpl有一个头文件,其中包含类CMemDCImpl的所有成员的定义,以及包含其实现的*.cpp文件.请帮我修复此错误.

c++ linker-errors lnk2005

7
推荐指数
1
解决办法
2万
查看次数

由于其他依赖库,在VS2010中链接googleTest会导致LNK2005

我有一个庞大而复杂的项目,最终得到了单元测试.我已经在Visual Studio 2010本地构建了googleTest 1.6.0,使用cmake构建的项目文件就像README指定的那样.

该项目有许多静态和动态链接的依赖库.其中许多是专有的.所有链接尝试都会产生220个这样的错误.这是一个抽样:

msvcprtd.lib(MSVCP100D.dll):错误LNK2005:"public:void __cdecl std :: _ Container_base12 :: _ Orphan_all(void)"(?_ Olphan_all @ _Container_base12 @std @@ QEAAXXZ)已在gtest.lib中定义(gtest-all. OBJ)

libcpmtd.lib(cerr.obj):错误LNK2005:"protected:char*__cdecl std :: basic_streambuf> :: _ Gndec(void)"(?_ Gndec @?$ basic_streambuf @ DU?$ char_traits @ D @ std @@@ std @@ IEAAPEADXZ)已在msvcprtd.lib中定义(MSVCP100D.dll)

LIBCMTD.lib(setlocal.obj):错误LNK2005:已在MSVCRTD.lib中定义_configthreadlocale(MSVCR100D.dll)

链接:警告LNK4098:defaultlib'MSVCRTD'与使用其他库冲突; use/NODEFAULTLIB:library LINK:警告LNK4098:defaultlib'LIBCMTD'与使用其他库冲突; 使用/ NODEFAULTLIB:库

致命错误LNK1169:找到一个或多个多重定义的符号

我已经尝试了/ NODEFAULTLIB标志,并且我试图忽略msvcprtd.lib,MSVCRTD.lib和LIBCMTD.lib,如建议的那样,但后来我遇到了未解决的符号......

项目和googleTest都使用x64,/ MP,/ MDd和no/clr进行编译.

我一直在玩编译器标志,想知道是否存在某种版本不匹配.在我理解的范围内,Dumpbin没有暗示我可能理解的任何东西.我希望有一个呃

linker-errors googletest visual-studio-2010 lnk2005

7
推荐指数
1
解决办法
6455
查看次数

已在lib中定义的标准库,导致链接器错误

不知道我在这里做错了什么,但是说我有:

foo.h中

class foo
{
public:
int Get10(std::wstring);
};
Run Code Online (Sandbox Code Playgroud)

Foo.cpp中

int foo::Get10(std::wstring dir)
{
   return 10;
};
Run Code Online (Sandbox Code Playgroud)

我将它编译为lib,如果我将lib包含在另一个项目中以及相关的头文件(foo.h)并尝试调用foo的实例:

foo f;
f.Get10(L"ABC");
Run Code Online (Sandbox Code Playgroud)

我收到链接器错误说:

错误1错误LNK2005:"public:__thiscall std :: _ Container_base12 ::〜_Container_base12(void)"(?? 1_Container_base12 @std @@ QAE @ XZ)已在foo.lib中定义(foo.obj)C:\ foo\msvcprtd .lib(MSVCP100D.dll)footest

任何想法为什么会这样?

c++ linker lnk2005

6
推荐指数
1
解决办法
2万
查看次数

LNK2005将静态openCV库与Visual Studio和QT Creator链接时出错

我构建了静态openCV 2.3库.我的项目目前使用动态的没有问题,但现在我想使用静态库.我将libs添加到我的.pro文件中:

LIBS += "C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_calib3d231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_contrib231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_core231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_features2d231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_flann231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_gpu231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_haartraining_engine.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_highgui231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_imgproc231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_legacy231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_ml231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_objdetect231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_ts231.lib" \
"C:\Program Files\openCV_VS_static\opencv\build\lib\Release\opencv_video231.lib"
Run Code Online (Sandbox Code Playgroud)

并包括目录:

INCLUDEPATH += "C:\Program Files\openCV_VS_static\opencv\build\include"
INCLUDEPATH += "C:\Program Files\openCV_VS_static\opencv\build\include\opencv"
Run Code Online (Sandbox Code Playgroud)

当我尝试构建时,我收到以下错误:

LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR100.dll)
LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR100.dll)
LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined …
Run Code Online (Sandbox Code Playgroud)

linker qt opencv lnk2005 visual-studio

6
推荐指数
2
解决办法
8418
查看次数

如何忽略LNK2005和LNK1169?

所以我有一个使用外部库的Visual Studio 2010项目,为了在没有LNK2005的情况下进行编译,我不得不在链接器设置中处理库的顺序.

我让它在发布模式下编译良好,但无论出于何种原因,我都无法在调试中没有LNK错误的情况下编译它.

是否通常无法忽略LNK2005并告诉链接器只使用他遇到的任何内容?

谢谢!

//编辑:这里是一些特殊问题输出的错误.但是我已经尝试以不同的方式解决这个问题,每个解决方案给我带来不同的链接器问题 因此,我正在寻找忽略LNK2005的一般解决方案

Error 7 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in Libcmtd.lib(typinfo.obj) ...\msvcprtd.lib(MSVCP100D.dll)

Error 8 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) ...\msvcprtd.lib(MSVCP100D.dll)

Error 9 error LNK2005: _exit already defined in Libcmtd.lib(crt0dat.obj) ...\msvcprtd.lib(MSVCP100D.dll)

Error 10 error LNK2005: __invalid_parameter already defined in Libcmtd.lib(invarg.obj) ...\msvcprtd.lib(MSVCP100D.dll)

...

Error 37 error LNK1169: one or more multiply defined symbols found

c++ linker-errors visual-studio-2010 lnk2005

5
推荐指数
2
解决办法
9184
查看次数