Unsafe code may only appear if compiling with /unsafe

来源:互联网 发布:浙江围棋 知乎 编辑:程序博客网 时间:2024/06/05 15:33

1、用VS2005,C++使用GDAL的动态库时,报编译错误

Error 28 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<struct GDALColorEntry,class std::allocator<struct GDALColorEntry> >::_Vector_const_iterator<struct GDALColorEntry,class std::allocator<struct GDALColorEntry> >(struct GDALColorEntry *,class std::_Container_base const *)" (??0?$_Vector_const_iterator@UGDALColorEntry@@V?$allocator@UGDALColorEntry@@@std@@@std@@QAE@PAUGDALColorEntry@@PBV_Container_base@1@@Z) match1.obj 

解决方法:Configuration Properties -> C/C++ -> Code Generation -> Runtime Library, make sure this is set to either "Multi-Threaded Debug DLL (/MDd)" if you are linking with the dll runtime or "Multi-Threaded Debug (/MTd)" if you are statically linking with the runtime.


2、用VS2005编译SharpMap/Branches/0.9.5中的SharpMap.Extensions时报错“Error103Unsafe code may only appear if compiling with /unsafe”

解决方法:在工程属性中勾选“Allow Unsafe code”

unsafe screenshot

3、VS2008无法捕捉到断点,调试的时候原来的断点处显示一个空心圆加一个右下角的警告图标的解决方案。

今天(2013年9月18日,牢记历史!)本来写代码调试得好好的,突然加了一句话以后无法调试了,原来红红的断点处在调试的时候变成了空心圆加一个右下角的警告图标,如果临时让断点生效,可以选择右键点击断点,Location,把Allow Source code to be different这个选项勾上,但是编译的时候又提示“the source file is different from when the module was built”,虽然点确定也能过去,但是问题始终是没有解决的,感觉应该是修改代码以后IDE不知哪里没更新,导致它认为两份源代码不一样

解决方案:

Tools-Options,选中Debugging选项卡,里面有个“Require source to exactly match...”的勾先去掉,然后稍微修改下代码,保存后,再把勾勾上,这样就好了。

4、VS2008在处理字符串的时候报错“”Error 4error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'char [1024]' to 'LPCWSTR'

这种涉及到普通字符转换为宽字符(W)的时候,需要在项目属性里Configuration Properties——General——Character Set,改为Use Multi-Byte Character Set,这样就不报错了,就可以通用了。

原创粉丝点击