Visual Studio-Error
总阅读次
记录visualstudio日常错误
- 链接错误Error C2371 ‘print’: redefinition; different basic types
1
2
3
4
5
6
7
8
9
10
11
12Severity 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
````
+ 函数定义 错误‘void’ illegal with all types1
2
3
4检查print函数名称是否正确
+ 函数声明中返回参数跟 使用过程中返回参数不一致
描述Severity Code Description Project File Line Suppression State1
2
3
4
5
6
7解决方法:
检查函数声明
cout 重载输入出运算符使用错误
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 9LNK1120 1 unresolved externals c-test_share D:\gx_workspace\share_gx-linux\VS_share\C\c-test_share\Debug\c-test_share.exe 11
2
3
4
5
6
# 无法解析到函数
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
1 |
|
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 |
|
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 |
|
fatal error C1083: Cannot open include file: ‘fstream.h’: No such file or directory
1 |
|
- install v141 build tools
1 | Severity Code Description Project File Line Suppression State |
解决办法:
选中工程项目,鼠标右键properties
—>Configuration properties
–>General
—>Platform Toolset
平台工具集的本质是msbuuild
其目录在C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0
Cannot open include file: 'stdafx.h
- 在项目中添加文件StdAfx.h;
注意到:要将这个文件添加进去即可,该文件的内容可以是空的,什么都没有,只要有这个文件即可;有这个文件就可以通过编译了。(而事实上,在项目文件夹中看不到这个文件,系统将其隐藏了!!!!)
[参考了网上博文][]
[参考了网上博文]: http://blog.163.com/yuyang_tech/blog/static/216050083201211310210206
_tmain
问题
VS2015报错1
2Severity 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
7D:\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 |
|
中#include<iostream.h>
是VC6以前的写法
应该用标准库的写法
1 |
|
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
解决:在报错代码顶部添加#define _CRT_SECURE_NO_WARNINGS
- LPTSTR’ to ‘const char 问题解决:
1
2Severity 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
- The build tools for v140 (Platform Toolset = ‘v140’) cannot be found.
1
错误 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
- 无法将参数 2 从“LPTSTR”转换为“const char *”代码报错的那条语句
1
错误 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
3char c_ALLShow_ComName[30];//显示用既串口名
int CSerial::OpenPort(LPTSTR lpszPortName,int i_BaudRate)
在vs2015(v140)却不会报这个错,在vs2013(v120)却会报这个错
- 项目字符编码问题
1
2
31>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 | 1>------ 已启动全部重新生成: 项目: DLL_ICardRecycleImpl, 配置: Debug x64 ------ |
解决:
编译模式方式不同,lib、dll文件是win32编译生成的,使用的工程代码也要用win32才行喔
visualstudio已停止工作系列
使用vs自带Developer Command Prompt for VS2015
输入devenv /safemod
visualstudio无法停留在断点或者 运行程序 一闪而过
1 | The thread 0x206c has exited with code 0 (0x0). |