C++ 常见问题

1:保证编译后方法名不被修改:  The: extern "C" { function declarations here in h file } will disable C++ name encoding. so c# will find the function

1: definition of dllimport function not allowed

×××_EXPORT 宏定义不对: ***_EXPORT into the property sheet's section C/C++ > Preprocessor > Preprocessor Definitions

 2:(.Net DllImport) p/invoke 默认的CallingConvention 是 __stdcall ,而VS c++ 方法默认的CallingConvention是  _cdecl 

解决方法:

  • Use __stdcall for the C declaration or CallingConvention.Cdecl in the C# declaration

3:启用非托管代码调试 dll 调试

类引用

只能引用类的头文件(.h)--即定义的类必须有头文件,不能直接引用实现文件(.cpp)

名字修饰约定extern "C"与extern "C++"浅析

设置.pch 

建立C++解决方案时,会生成SolutionName.sdf和一个叫做ipch的文件夹,这两个文件再加上*.pch等文件使得工程变得非常的庞大,一个简单的程序都会占用几十M的硬盘容量,可惜毕竟硬盘还没有廉价到免费的地步。
那么,该怎么解决呢?

方法:
Tools->Options->Text Editor->C/C++->Advanced,在 Fallback Location 的属性组中,将"Always Use Fallback Location"设置为 true,将"Do Not Warn If Fallback Location Used" 设置为 true ,然后删除解决方案目录下的 sdf 文件和 ipch 目录,再次打开解决方案,发现这些烦人的东西已经不见了。
那么那些文件放置到那里了呢?看 "Fallback Location" 属性说明:这是存储浏览信息数据库和 IntelliSense 文件的第二个位置,如果不指定则放置到临时目录中;到临时目录一看,里面有一个 VC++ 的目录,都在那个目录里面呢。
可以在 "Fallback Location" 属性中,设置一个固定的路径来存储这些文件,比如D:VS2010Temp,这样也比较好管理这些庞大的臃肿的文件,可以定期清理掉它们,释放出硬盘空间!

Error: forget to add '#include "stdafx.h"' to your source

 

在VC9增加一个类调试时出现 “forget to add '#include "stdafx.h"' to your source” 时,是在编译时使用了预编译头文件,所以需要设置不用 Precompiled Header.Project-->Property-->Configuraton Properties-->C/C++-->Precompiled Header-->Create/use Precompiled Header-->Not Using Precompiled Headers.

_SCL_SECURE_NO_WARNINGS

报错:

1>c:program files (x86)microsoft visual studio11.0vcincludexutility(2176): error C4996: 'std::_Copy_impl': Function callwith parameters that may be unsafe - this call relies on the caller to checkthat the passed values are correct. To disable this warning, use-D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'CheckedIterators'

加入预处理器(项目属性----C/C++----预处理----预处理器定义):
_SCL_SECURE_NO_WARNINGS

断点无法命中的解决办法

  • 1,首先要保证每个项目的配置管理器中都设置为Debug模式。
  • 2, 项目-〉属性-〉配置属性-〉C/C++-〉代码生成->运行时库,修改成多线程调试(/MTD)
  • 3,项目-〉属性-〉配置属性-〉链接器-〉调试-〉生成调试信息,这里设为“是”。
  • 4,项目-〉属性-〉配置属性-〉C/C++-〉常规-〉调试信息格式,这里不能为“禁用”。
原文地址:https://www.cnblogs.com/grayguo/p/5398403.html