当前位置: 首页 > article >正文

调试编译错误信息总结

目录

通用问题

具体问题

0  unresolved external symbol 

情况一:

情况二  :

其它问题

1、使用add 新增了一个类,后来发现不需要,又把生成的类的文件删除了,然后编译出错

2 动态加载DLL,总是不成功

3 vs调试正确显示utf8格式字符串

4 vc\include\xrefwrap(283): error C2440: 'return' : cannot convert from 'void' to 'bool'

5 studio 12.0\vc\include\assert.h(32): error C2143: syntax error : missing ';' before 'string'

6 libc.lib

7 A copy of xx.hwas found in but the current source code is different from the version built into

8 VS 加载符号

9 将文件夹删除后,连接时还在提示缺少文件

10 提升堆栈大小

11 编译错误

12 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'tagLiveStreamUser' (or there is no acceptable conversion)

13 _CRT_SECURE_NO_WARNINGS 

14 fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source

15 error LNK2001: unresolved external symbol "__declspec(dllimport) const CXXX::`vftable'" 

16 加了头文件 但还是显示 error C2065: 'fstream' : undeclared identifier

17、当前不会命中断点,还没有为该文档加载任何符号

18、 fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include

19、 error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)

20、pure virtual function call

21、error LNK2005  已经在...文件中定义

22、error C2039: 'wstring' : is not a member of 'std'

23、error C2146: syntax error : missing ';' before identifier 

24、 error C2027: use of undefined type 'std::tuple_element<0,_Ftuple>'

25、openssl 64 LIB 加载后,出现error LNK2019: unresolved external symbol __imp_CertFreeCertificateContext referenced in function capi_free_key

26、error LNK2019: 无法解析的外部符号 __imp_PathFileExistsA,

27、error LNK2001: unresolved external symbol _snprintf

28、error C2011: “sockaddr”:“struct”类型重定义错误

29、error C2601:  local function definitions are illegal


通用问题

  debug下正常,release下崩溃

   大部分是变量未初始化,debug 、release下 变量未初始化时,给的默认值不同

   

具体问题

0  unresolved external symbol 

    error LNK2019: unresolved external symbol 

    error LNK2001: unresolved external symbol

 

情况一:

   更新网易播放器SDK时,发生了这个错误

   明明在项目路径中,添加了新的.h 和.cpp文件,为什么链接阶段会找不到.h中定义的函数呢

   这就需要理解:

   #include".h"     头文件的意义,我们在程序中,用的很多系统库函数,需要添加相应的头文件,然后就可以使用了

                                                    想当然的,如果是自己编写的或拷贝的别人的文件,如果只include进头文件来就可以用了么

                                                    答案未必,这就需要理解:为什么系统库函数可以直接加头文件,而自己写的或拷贝到路径的文件,只添加头文件时,却不行呢?

                                                    原因:

                                                   1)系统库函数只添加头文件就可以使用,是因为是系统库,系统能找到这些库中编译好的库函数位置。

                                                   2)我们自己写的,如果不把源文件添加到项目中的话,虽然能编译过去,但链接的时候,如果有地方使用里面的相关函数,则会找不到相应的实现,于是发生2019类似这样链接错误,因为链接器找不到,确实找不到呀,链接器相比也很委屈,臣妾实在做不到啊。  因为,因为,你没有将源码加入项目,所以无法编译源码,所以链接时,只找到了函数声明,却未找到函数定义,实在不是链接器不给力,而是确实是我们自己的原因。 你要想做菜,不能只给菜单,还要给买好菜才行,要不就是巧妇也做不出来,你要想使用这个函数,你不能光声明个函数,也不能实现了这个函数就完事,你还得给我拿来让我放锅里用才行吧。

                                                  解决方法也很简单,自己写的,或是拷贝别人的 将.H  .CPP 添加到项目中, 对于lib等外部库出现这种情况,则很可能是.H、和LIB 不对应造成的,需要更新对应版本

                   

补充:

     c++控制台中调用对话框   MessageBoxExA时,出现链接错误

     error LNK2019: unresolved external symbol __imp__MessageBoxExA@20 referenced in function _wmain

     原因:

     控制台调用对话框需要两个条件:

     1)  #include <windows.h>

     2) 加入user32.lib 

           #pragma comment(lib,"user32.lib") //加上这个lib 才能调用消息对话框,否则出错

    

   补充2:

   将原本闭源的duilib替换为开源duilib后,出现下面链接错误

    duilib_d.lib(Combo.obj) : error LNK2005: "public: int __thiscall ui::Combo::GetCurSel(void)const " (?GetCurSel@Combo@ui@@QBEHXZ) already defined in desktopTool_form.obj       

               

项目使用了很多依赖项,使用引用的方式添加进来, 更换后,可能依懒项受影响了

重新加入进来即可

具体步骤:项目属性页-->通用属性-->框架和引用

                               

示例1 

类中声明了 静态变量

如果CPP中没有定义的话,会出现     error LNK2001: unresolved external symbol 

静态变量类H中声明static nbase::NLock s_InstListLock[CALLBACK_COUNT]; //几个回调就几个锁static std::set<LsSession*> s_stInstList;需要在CPP中定义才行nbase::NLock LsSession::s_InstListLock[CALLBACK_COUNT];std::set<LsSession*> LsSession::s_stInstList;否则会出现2001错误

                           

情况二  :

        Git pull时,出现了error 2001错误

        

原因:

      找lib时,先在公共lib库部分找,找不到的时候,再去其它lib库里找

      之所以,GITPULL 后,会出现这个错误

      是因为,修改了lib库文件,修改后的文件保存在了debug目录下

      但是旧的lib库,保存在公共下了,

      这时候加载公共lib下的旧lib, 自然出现了lib库不配对情况

解决:

     将公共lib下的旧的lib删除即可

其它问题

1、使用add 新增了一个类,后来发现不需要,又把生成的类的文件删除了,然后编译出错

出错信息如下:

fatal error C1083: Cannot open source file: 'MyClass.cpp': No such file or directory

我建立了一个类MyClass,后来发现不需要,就打开项目文件夹,将 此类对应的.h,cpp删除了,再编译的时候出现上述错误。

原因是:虽然删除了文件,但是解决方案中,还保留着MyClass信息,解决方案中并没有删除。

方法:

2 动态加载DLL,总是不成功

  原因路径没设置好,EXE设置在BIN路径

  但是debugging调试的路径,却不是bin, 将其设置为相同路径就好了,当然动态加载的这个dll也要放在bin文件夹里

  

3 vs调试正确显示utf8格式字符串

自从将visual studio从2010升级到2015后,发现调用接口的utf8格式字符串不能正常显示了,常常被莫名其妙截断,查了下,原来可以直接将变量拖到watch窗口中,在变量名后面手动添加,s8予以解决,

总结如下:

,s8:将字符串转成unicode展示

,数字  将变量拆分为数组显示, 数字是要显示多少位, 此法对const char*这类原始字符串非常有用

,x 16进制查看

,hr  查看Windows HRESULT解释

,wm Windows消息,例如0x0010, wm 显示 WM_CLOSE

4 vc\include\xrefwrap(283): error C2440: 'return' : cannot convert from 'void' to 'bool'

// non-const class member function 
template<class R, class C, class... DArgs, class P, class... Args>
auto Bind(R(C::*f)(DArgs...), P && p, Args && ... args) ->WeakCallback<decltype(std::bind(f, p, args...))>
{std::weak_ptr<WeakFlag> weak_flag = ((SupportWeakCallback*)p)->GetWeakFlag();auto bind_obj = std::bind(f, p, args...);static_assert(std::is_base_of<nbase::SupportWeakCallback, C>::value, "nbase::SupportWeakCallback should be base of C");WeakCallback<decltype(bind_obj)> weak_callback(weak_flag, std::move(bind_obj));return weak_callback;
}}

绑定使用:

	camera_out_quality_list_combo->AttachSelect(nbase::Bind(&DetectForm::OnVideoQualitySelected, this));

定义成了   void OnVideoQualitySelected();

        应该定义成 bool 类型,就可以了 

        bool OnVideoQualitySelected(); 

5 studio 12.0\vc\include\assert.h(32): error C2143: syntax error : missing ';' before 'string'

  vs崩溃后,重启重运行,跳出这么奇怪的系统文件错误

  当然,系统文件是肯定不会错的

 原因:

class MyForm{

};  //此处的分号不见了,将其添加上就可以了

6 libc.lib

老的项目会有这个库的问题

解决方法:

忽略这个库

但我使用另一种解决方式时:

down vote

I had this problem in MS VC++ 2012 Express with Windows SDK 7.1.

I found this solution from the DISLIN developers :


  (i) in MS VC++\Project\<YourProject> Properties pull-down...(ii) <YourProject>Property Pages\Ignore Specific Default Libraries : libc.lib
(iii) <YourProject>Property Pages\Additional Dependencies\Edit : libcmt.lib

添加了libcmt.lib  反而有更多冲突

解决方法:

只需要忽略libc.lib就可以,但这个时候你可能还不成功

这时候还需要运行环境匹配

比如:

1)共享库

匹配的代码生成运行库

2)静态库

匹配的是

7 A copy of xx.hwas found in <long directory path> but the current source code is different from the version built into <the exact same long directory path>

  1. Close the window of the .h file in Visual Studio if it's open.
  2. Close Visual Studio.
  3. CUT the .h file from its normal location and paste it into a temporary folder that VS doesn't know about.
  4. Restart VS and compile. It'll complain about the missing .h file. Good -- Make the bastard beg for it!
  5. Paste the .h file back into its original location.
  6. Compile. VS will gratefully accept the missing file. (Damn I hate Microsoft!)

    

我的解决方案:

    关闭vs,

    将受影响的文件,剪切到另一个文件夹保存

    开启vs,重新编译运行  出错

    将那个文件,再剪切到原来的位置

    重新编译 运行  正常

8 VS 加载符号

在使用VS2013开发项目时,偶尔会遇到编译通过后,调试时提示:“正在从以下位置加载xxx.dll的符号”,而这些dll一般都是MS或其他第三方提供的底层基础文件的dll。

加载的过程一般非常慢,这一般是编写的代码有错误,如“访问了野指针”,最终崩溃在MS等提供的底层代码中,而为了定位底层具体错误代码位置需要访问这些dll对应的pdb之类的文件(通常需要从MS的服务器上下载调试文件),但这些具体的调试文件我们一般用不到,也不想看。

如何解决:在[工具]-->[选项]-->[调试]-->[符号]中奖pdb的文件不选择ms服务器 、清空、退出 、重新运行

9 将文件夹删除后,连接时还在提示缺少文件

fatal   error   C1083:   Cannot   open   source   file

c1xx : fatal error C1083: Cannot open source file

解决方法:

项目.vcxproj 用文本方式打开

手动将那些已经无用的include文件 删除

注意要小心,不要删错了  

10 提升堆栈大小

    运行时遇到了 runtime error

    没找到别的原因

    可能是堆栈大小不足

    

    VS默认堆栈1M

    当程序中定义了较大局部变量,会超过vs默认栈大小1M,程序会自动退出 

    直接输入4*1024*1024编译不通过  输入4194304即可

   

11 编译错误

  编译时突然出现 SDK头文件中 的错误,而头问题之前还能编译成功,且并没有改动,也没有错误

  那可能是头文件编码问题

  我挨个的将头文件改成  带有BOM的UTF-8 格式后,可以了

12 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'tagLiveStreamUser' (or there is no acceptable conversion)

结构体中重载了==

typedef struct tagLiveStreamUser {uint64_t uid;bool primaryUser;bool operator==(const tagLiveStreamUser& node){return this->uid == node.uid;}bool operator==(const int&uid){return this->uid == uid;}} LIVE_STREAM_USER;

将结构体放入VECTOR容器中,

再执行        

std::string account
auto it = std::find(liveUses_.begin(), liveUses_.end(), account);

报错,因为== 没有定义 string类型转换

13 _CRT_SECURE_NO_WARNINGS 

   安全策略,比如强制让你加 _s,不然就提示错误

  添加 _CRT_SECURE_NO_WARNINGS

    

14 fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source

添加另一项目的源文件后,提示这个

但是在这个文件上 直接添加#include "stdafx.h" 会引起其它问题

解决方式:

选中这个文件,右击属性,设置不使用预定义头

15 error LNK2001: unresolved external symbol "__declspec(dllimport) const CXXX::`vftable'" 

导出类,使用这个LIB的工程需要加宏定义

这个导出库是这么定义的


#ifndef HW_EPUBSDK_EXPORTS
#define EPUB_EXPORT  __declspec(dllimport)
#else 
#define EPUB_EXPORT __declspec(dllexport)
#endif

所以,使用这个库的工程加上如下宏定义

16 加了头文件 但还是显示 error C2065: 'fstream' : undeclared identifier

#include <fstream> 
#include <iostream> 

原因 没加std命名空间,因为这些类都是定义在std命名空间中

加上就好了

#include <fstream> 
#include <iostream> 
using namespace std;

17、当前不会命中断点,还没有为该文档加载任何符号

突然不能调试了,可以清理下项目,然后重新开始

18、 fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

想在控制台程序中 使用 CFile

添加了 #include <afx.h>

然后出现了这个错误

解决方法:  在cpp 中,把afx.h  放到所有include的最前面

19、 error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)

把 afx.h放在最前面后,又出现这个BUG

添加

uafxcwd.lib

20、pure virtual function call

调用了一个没有实例化的纯虚函数

如:

class IntForm :public nim_comp::WindowEx
{
public:IntForm();~IntForm();/*** 一下三个接口是必须要覆写的接口,父类会调用这三个接口来构建窗口* GetSkinFolder		接口设置你要绘制的窗口皮肤资源路径* GetSkinFile			接口设置你要绘制的窗口的 xml 描述文件* GetWindowClassName	接口设置窗口唯一的类名称*/virtual std::wstring GetSkinFolder() override;virtual std::wstring GetSkinFile() override;virtual std::wstring GetWindowClassName() const override;virtual bool OnClicked(ui::EventArgs* msg);/*** 收到 WM_CREATE 消息时该函数会被调用,通常做一些控件初始化的操作*/virtual void InitWindow() override;//void OnInitLayout() override;/*** 收到 WM_CLOSE 消息时该函数会被调用*/virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);public:static const LPTSTR kClassName;ui::ListBox* pHListBox_ = nullptr;};

父类:

class WindowEx : public ui::WindowImplBase
{
public:WindowEx();virtual ~WindowEx();virtual HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, bool isLayeredWindow = true, const ui::UiRect& rc = ui::UiRect(0, 0, 0, 0)) override;virtual LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);virtual void OnEsc(BOOL &bHandled);virtual std::wstring GetWindowClassName(void) const = 0;virtual std::wstring GetWindowId(void) const = 0;virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);void ActiveWindow();  //激活窗口void SetTaskbarTitle(const std::wstring &title);private:bool RegisterWnd();void UnRegisterWnd();
};

父类的纯虚函数

    virtual std::wstring GetWindowId(void) const = 0;

没有在子类中实现,  所以初始化子类时,出现了上述错误

21、error LNK2005  已经在...文件中定义

可以在命令行中,加入如下命令

/FORCE:MULTIPLE

22、error C2039: 'wstring' : is not a member of 'std'

#include <string.h>
std::wstring 

这里注意 #include <string.h>  #include <string>  不同

正确的应该是

#include <string>

23、error C2146: syntax error : missing ';' before identifier 

BOOL bHasVerified;

编译错误:>d:\biancheng\xnw2.0\test\purexnwcef\xnw-live\module\myhelper\reg\Reg.h(20): error C2146: syntax error : missing ';' before identifier 'bHasVerified'

原因,没有添加BOOL 的头文件,  将BOOL 改成 bool 就可

同理, TCHAR  改成 wchar_t

有时候为了尽可能少添加头文件,就造成了这样的编译错误 

24、 error C2027: use of undefined type 'std::tuple_element<0,_Ftuple>'

          error C2977: 'std::add_reference' : too many template arguments

原因 回调函数多写了参数

typedef std::function<void(void)> IntCountCB;void SetIntCountCB(IntCountCB cb)
{countCB_ = cb;
}void IntForm::OnListCountChanged()
{int nTotalCount = GetProvider()->GetElementtCount();int nChosen = GetProvider()->GetCountOfChosen();std::wstring str;str = nbase::StringPrintf(L"已选择(%d/%d)", nChosen,nTotalCount);pIntCountLabel_->SetText(str);
}pHVHListBox_->SetIntCountCB(nbase::Bind(&IntForm::OnListCountChanged,this, std::placeholders::_1));

最后一句 改成如下,就可以了

	pHVHListBox_->SetIntCountCB(nbase::Bind(&IntForm::OnListCountChanged,this));

25、openssl 64 LIB 加载后,出现error LNK2019: unresolved external symbol __imp_CertFreeCertificateContext referenced in function capi_free_key

https://github.com/microsoft/vcpkg/issues/6308

Per the OpenSSL notes for windows, when linking openssl static libraries, crypt32 should be part of the libraries to be linked as well.

26、error LNK2019: 无法解析的外部符号 __imp_PathFileExistsA,

#pragma comment(lib, "Shlwapi.lib")

27、error LNK2001: unresolved external symbol _snprintf

vs2013 出现这个错误

vs2019正常

void
qrSetErrorInfo3(QRCode *qr, int errnum, const char *fmt, ...)
{char info[QR_ERR_MAX];va_list ap;qr->errcode = errnum;va_start(ap, fmt);vsnprintf(&(info[0]), QR_ERR_MAX, fmt, ap);va_end(ap);snprintf(&(qr->errinfo[0]), QR_ERR_MAX, "%s%s", qrStrError(errnum), info);
}

原因:

  1. snprintf()函数并不是标准c/c++中规定的函数,所以在许多编译器中,厂商提供了其相应的实现的版本。VS中称为_snprint

  2. 将其改为_snprintf 就可以了
  3. 也可以在预编译处定义  
    #if _MSC_VER
    #define snprintf _snprintf
    #endif

28、error C2011: “sockaddr”:“struct”类型重定义错误

在 #include<windows.h>之前 先 #include <winsock2.h>

更彻底的是添加 WIN32_LEAN_AND_MEAN 

29、error C2601:  local function definitions are illegal

以下代码 在VS2013出现上述错误 ,在VS2019正常

std::wstring GetParentDir(std::wstring curDir)
{std::wstring dir = curDir;TCHAR ch = dir.back();if(ch=='\\'||ch=='/')dir.erase(dir.size() - 1);                   //去掉最后的路径分隔符int nLineIndex = dir.rfind(L"\\");std::wstring parentDir = dir.erase(nLineIndex + 1);     //上一层目录return parentDir;  //带\\分隔符
}

改成  ,

又提示 没有返回值

std::wstring GetParentDir(std::wstring curDir)
{std::wstring dir = curDir;TCHAR ch = dir.back();if(ch=='\\'||ch=='/')dir.erase(dir.size() - 1);                   //去掉最后的路径分隔符int nLineIndex = dir.rfind(L"\\");std::wstring parentDir = dir.erase(nLineIndex + 1);     //上一层目录//带\\分隔符return parentDir;  
}

最终,把最后的注释改成/*后,在VS2013才通过

std::wstring GetParentDir(std::wstring curDir)
{std::wstring dir = curDir;TCHAR ch = dir.back();if(ch=='\\'||ch=='/')dir.erase(dir.size() - 1);                   //去掉最后的路径分隔符int nLineIndex = dir.rfind(L"\\");std::wstring parentDir = dir.erase(nLineIndex + 1);     //上一层目录/*/带\\分隔符*/return parentDir;  
}

30、c#项目 error MSB3172: 无法读取清单“Properties\app.manifest”

项目右键属性

我没做什么,重新点击下 ,再运行就好了

31、 error RC2104: error RC2104:

MFC项目 ,修改资源中的,VS_VERSION_INFO 时,

再编译出现如下错误

Import.rc(412): error RC2104: undefined keyword or key name: DS_SETFONT

结局方案:

资源文件中,添加

#include <winresrc.h>

 

参考: c++ Runtime Error 是怎么回事,怎么解决_百度知道

http://www.lryc.cn/news/2419705.html

相关文章:

  • oracle 如何实现excel的正态分布函数normdist
  • CAPLE实现CAN路由的自动化测试
  • 应用层与驱动层通信DeviceIoControl
  • GoYouBBS: 基于Go语言构建的强大论坛系统
  • 渗透测试工程师——第一部分 信息扫描实验系列 001主机存活性探测实验
  • Android布局基础知识:wrap_content,match_parent,layout_weight
  • 树莓派安装MJPG-streamer
  • GALGAME文字提取agth 特殊码大全(特殊码表)和使用方法
  • delphi中使用MSWINSCK.OCX控件
  • 私库如何区分正式和测试环境独立的库
  • md5值是什么意思_详解:PER?霍林格效率值?这个最火的高阶数据究竟是什么意思?...
  • 正在载入中......loading页面的几种方法
  • c++求矩阵的秩_Matlab:矩阵的秩,简化梯形矩阵和线性方程组
  • 【C语言】:static和extern的详细介绍和使用
  • softcore -- CPU rasterization
  • xp序列号大全可通过正版验证的XP序列号发布
  • SolrIK分词器-简单介绍与安装
  • MouseArea组件和MouseEvent事件在Qt中是经常使用的重要组件和事件。本文将详细介绍MouseArea组件和MouseEvent事件的用法,并提供...
  • TTYL的完整形式是什么?
  • mongo执行命令: not authorized on admin to execute command
  • 【渝粤教育】电大中专电商运营实操12作业 题库
  • nbtscan局域网扫描的原理
  • VS各个版本之间2005、08、10、12...转换
  • NumberFormat类
  • WritePrivateProfileString() 用法
  • 新发的日常小实验——使用IETester测试不同IE版本的浏览器,测试网页JS的兼容性(console未定义兼容测试)
  • cpio命令的常用方法
  • stm32串口反相输出 SP3232输出反相解决办法
  • FindWindowEx 遍历所有窗口
  • AV1编码各种浏览的版本支持