文章目录
  1. 1. 无法解析到函数
  2. 2. 无法解析的外部符号 链接错误
  3. 3. visualstudio已停止工作系列
  4. 4. visualstudio无法停留在断点或者 运行程序 一闪而过

angry-hulk
记录visualstudio日常错误

  • 链接错误

    1
    2
    3
    4
    5
    6
    7
    Severity	Code	Description	Project	File	Line	Suppression State
    Error LNK2019 unresolved external symbol _clrscr referenced in function _disprep Supermarket D:\Code\S-SuperMarket\Supermarket\Supermarket\Source-SuperMarket.obj 1


    Severity Code Description Project File Line Suppression State
    Error LNK1120 1 unresolved externals Supermarket D:\Code\S-SuperMarket\Supermarket\Debug\Supermarket.exe 1
    `
  • 函数定义 错误

1
Error	C2371	'print': redefinition; different basic types

检查print函数名称是否正确

  • 函数声明中返回参数跟 使用过程中返回参数不一致
    描述
    1
    'void' illegal with all types

解决方法:
检查函数声明  与使用过程中函数是否一致。

cout 重载输入出运算符使用错误

1
2
3
4
5
6
7
8
9
10
Severity	Code	Description	Project	File	Line	Suppression State
Error C2784 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char &)': could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,signed char *)': could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char &)': could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &&,_Ty &)': could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &&' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<char,_Traits> &std::operator >>(std::basic_istream<char,_Traits> &,unsigned char *)': could not deduce template argument for 'std::basic_istream<char,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem &)': could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error (active) no operator ">>" matches these operands c++_test d:\Project_VS\C++\C++_test\c++_test\c++_test\c++_test_Source.cpp 9
Error C2676 binary '>>': 'std::ostream' does not define this operator or a conversion to a type acceptable to the predefined operator c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9
Error C2784 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,_Elem *)': could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ostream' c++_test d:\project_vs\c++\c++_test\c++_test\c++_test\c++_test_source.cpp 9

无法解析到函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
LNK1120	1 unresolved externals	c-test_share	D:\gx_workspace\share_gx-linux\VS_share\C\c-test_share\Debug\c-test_share.exe	1

LNK2019 unresolved external symbol _factoriald referenced in function _main c-test_share D:\gx_workspace\share_gx-linux\vs_share\c\c-test_share\c-test_share\c-test_share.obj 1

```


检查factoriald 函数,是main函数里这个函数名打错,导致编译器找不到函数





# 不支持默认整型

1>d:\gx_workspace\share_gx-linux\vs_share\c++_test_source.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1
2
3
4
5
6
7
8
9
10
11
12


分析:代码中函数没有写返回值类型,编译器将其视为默认整型。但是visualstudio不支持默认整型。

填写代码函数返回类型(可以写void)




# v120 cannot be found

错误代码`The build tools for v120 (Platform Toolset = 'v120') cannot be found`

1>—— Build started: Project: MainProcess, Configuration: Debug Win32 ——
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = ‘v120’) cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting “Retarget solution”.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

1
2
3
4
5
6
7
8
9
10
11

解决办法:

在工程鼠标右键点击:
`Properites`-->`Configuration Properties`-->`General`-->`Platform Toolset`-->Visual Studio 2012(v110) 即可
如果在`Platform Toolset`提`Visual Studio 2013(v120)(no installed)`则....不知道怎么办(待解决)


# 没有找到头文件

1. Canot open include file:`fstream.h`:No such file or directory

fatal error C1083: Cannot open include file: ‘fstream.h’: No such file or directory

1
2
3

解决办法:
```#include <fstream.h>

改成

1
2
#include <fstream>
using namespace std;

  • install v141 build tools
1
2
Severity	Code	Description	Project	File	Line	Suppression State
Error MSB8020 The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". test_win32 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets 57

解决办法:

选中工程项目,鼠标右键properties —>Configuration properties–>General—>Platform Toolset

平台工具集的本质是msbuuild其目录在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0

  • Cannot open include file: 'stdafx.h
  1. 在项目中添加文件StdAfx.h;

注意到:要将这个文件添加进去即可,该文件的内容可以是空的,什么都没有,只要有这个文件即可;有这个文件就可以通过编译了。(而事实上,在项目文件夹中看不到这个文件,系统将其隐藏了!!!!)

[参考了网上博文][]




[参考了网上博文]: http://blog.163.com/yuyang_tech/blog/static/216050083201211310210206
  • _tmain问题
    VS2015报错

    1
    2
     Severity	Code	Description	Project	File	Line	Suppression State
    Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) Client D:\gx_2017\0_2017-05\socket_first\Client\Client\MSVCRTD.lib(exe_main.obj) 1

    解决

    1
    extern "C" int _cdecl wmain(int argc, wchar_t* argv[]){ ......

    参考网页

  • Cannot open include file: ‘iostream.h’
    1
    2
    3
    4
    5
    6
    D:\Users\takethat\Desktop\temp\dll_temp>cl /c dll_nolib.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86
    Copyright (C) Microsoft Corporation. All rights reserved.

    dll_nolib.cpp
    dll_nolib.cpp(2): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

报错代码

1
2
3
#include<objbase.h>
#include<iostream.h>
using namespace std;

#include<iostream.h>是VC6以前的写法
应该用标准库的写法

1
2
#include <iostream > 
using namespace std;

  • This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details

解决:在报错代码顶部添加

_CRT_SECURE_NO_WARNINGS```
1





+ LPTSTR' to 'const char 问题

Severity Code Description Project File Line Suppression State
Error C2664 ‘char strcpy(char ,const char )’: cannot convert argument 2 from ‘LPTSTR’ to ‘const char ‘ DLL_ICardRecycleImpl d:\gx_2017\2017-07\0\dll_icardrecycleimpl\dll_icardrecycleimpl\windowsserial.cpp 301

1
2
3
4
5
6
7
8
9
10
11
解决:









+ The build tools for v140 (Platform Toolset = 'v140') cannot be found.

错误 1 error MSB8020: The build tools for v140 (Platform Toolset = ‘v140’) cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting “Upgrade Solution…”. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5 DLL_ZBLCommunication

1
2
3
4
5
6
7






+ 无法将参数 2 从“LPTSTR”转换为“const char *”

错误 1 error C2664: “char strcpy(char ,const char )”: 无法将参数 2 从“LPTSTR”转换为“const char ” C:\Users\sky\Desktop\ICardRecycleImpl_SZ7A\DLL_ICardRecycleImpl\DLL_ICardRecycleImpl\WindowsSerial.cpp 301 1 DLL_ICardRecycleImpl

1
代码报错的那条语句

strcpy(c_ALLShow_ComName,lpszPortName);
1
2
3
4
5
参数原型:
```C++
char c_ALLShow_ComName[30];//显示用既串口名

int CSerial::OpenPort(LPTSTR lpszPortName,int i_BaudRate)

在vs2015(v140)却不会报这个错,在vs2013(v120)却会报这个错

  • 项目字符编码问题
    1
    2
    3
    1>g:\vs_project\vs2017_temp\test_2017\test_2017\test_source.cpp(19): error C2440: 'initializing': cannot convert from 'WCHAR [260]' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
    1>g:\vs_project\vs2017_temp\test_2017\test_2017\test_source.cpp(19): note: No constructor could take the source type, or constructor overload resolution was ambiguous
    1>Done building project "Test_2017.vcxproj" -- FAILED.

实际解决:

是将Project Properties中的Configureation Properties->General->Character Set = Not Set,重新编译即可

请阅读这篇文章 http://blog.csdn.net/luoweifu/article/details/49382969

无法解析的外部符号 链接错误

已经在工程属性中添加了lib文件,但是仍然提示连接错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1>------ 已启动全部重新生成:  项目: DLL_ICardRecycleImpl, 配置: Debug x64 ------
1> stdafx.cpp
1> WindowsSerial.cpp
1> DLL_ICardRecycleImpl.cpp
1> CCardRecycle_SZ7A.cpp
1>CCardRecycle_SZ7A.cpp(383): warning C4800: “int”: 将值强制为布尔值“true”或“false”(性能警告)
1>CCardRecycle_SZ7A.cpp(385): warning C4800: “int”: 将值强制为布尔值“true”或“false”(性能警告)
1>CCardRecycle_SZ7A.cpp(388): warning C4800: “int”: 将值强制为布尔值“true”或“false”(性能警告)
1>CCardRecycle_SZ7A.cpp(942): warning C4390: “;”: 找到空的受控语句;这是否是有意的?
1> 正在生成代码...
1> dllmain.cpp
1> 正在创建库 C:\Users\sky\Desktop\ICardRecycleImpl_SZ7A\DLL_ICardRecycleImpl\x64\Debug\DLL_ICardRecycleImpl.lib 和对象 C:\Users\sky\Desktop\ICardRecycleImpl_SZ7A\DLL_ICardRecycleImpl\x64\Debug\DLL_ICardRecycleImpl.exp
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: __cdecl CMITDLL::CMITDLL(void)" (??0CMITDLL@@QEAA@XZ),该符号在函数 "public: __cdecl CCardRecycle_SZ7A::CCardRecycle_SZ7A(void)" (??0CCardRecycle_SZ7A@@QEAA@XZ) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: virtual __cdecl CMITDLL::~CMITDLL(void)" (??1CMITDLL@@UEAA@XZ),该符号在函数 "public: virtual void * __cdecl CMITDLL::`vector deleting destructor'(unsigned int)" (??_ECMITDLL@@UEAAPEAXI@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl CMITDLL::fnTestShow(int)" (?fnTestShow@CMITDLL@@QEAAXH@Z),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::setLogWorkMode(int,int)" (?setLogWorkMode@CCardRecycle_SZ7A@@QEAAHHH@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: int __cdecl CMITDLL::fnOpenCom(unsigned char *,int,int)" (?fnOpenCom@CMITDLL@@QEAAHPEAEHH@Z),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::initialization(char *,int)" (?initialization@CCardRecycle_SZ7A@@QEAAHPEADH@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: int __cdecl CMITDLL::fnCloseCom(void)" (?fnCloseCom@CMITDLL@@QEAAHXZ),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::initialization(char *,int)" (?initialization@CCardRecycle_SZ7A@@QEAAHPEADH@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: int __cdecl CMITDLL::Communication_SendRecv(unsigned char,unsigned char,unsigned char *,unsigned char *,int,int)" (?Communication_SendRecv@CMITDLL@@QEAAHEEPEAE0HH@Z),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::getStatus(struct stCardRecycleStatus &)" (?getStatus@CCardRecycle_SZ7A@@QEAAHAEAUstCardRecycleStatus@@@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: int __cdecl CMITDLL::MIT_Arm7DownloadProgram(char *,char *)" (?MIT_Arm7DownloadProgram@CMITDLL@@QEAAHPEAD0@Z),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::updateEquipmentBin(char *,char *)" (?updateEquipmentBin@CCardRecycle_SZ7A@@QEAAHPEAD0@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl CMITDLL::EnterProtect(void)" (?EnterProtect@CMITDLL@@QEAAXXZ),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::getStatus(struct stCardRecycleStatus &)" (?getStatus@CCardRecycle_SZ7A@@QEAAHAEAUstCardRecycleStatus@@@Z) 中被引用
1>CCardRecycle_SZ7A.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl CMITDLL::LeaveProtect(void)" (?LeaveProtect@CMITDLL@@QEAAXXZ),该符号在函数 "public: int __cdecl CCardRecycle_SZ7A::getStatus(struct stCardRecycleStatus &)" (?getStatus@CCardRecycle_SZ7A@@QEAAHAEAUstCardRecycleStatus@@@Z) 中被引用
1>C:\Users\sky\Desktop\ICardRecycleImpl_SZ7A\DLL_ICardRecycleImpl\x64\Debug\DLL_ICardRecycleImpl.dll : fatal error LNK1120: 9 个无法解析的外部命令
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========

解决:

编译模式方式不同,lib、dll文件是win32编译生成的,使用的工程代码也要用win32才行喔

导致“无法解析的外部符号”的可能情况


visualstudio已停止工作系列

使用vs自带Developer Command Prompt for VS2015输入devenv /safemod

visualstudio无法停留在断点或者 运行程序 一闪而过

1
2
The thread 0x206c has exited with code 0 (0x0).
The program '[7692] DateExample.exe' has exited with code 0 (0x0).
文章目录
  1. 1. 无法解析到函数
  2. 2. 无法解析的外部符号 链接错误
  3. 3. visualstudio已停止工作系列
  4. 4. visualstudio无法停留在断点或者 运行程序 一闪而过