VS 2008中CRT调用_osfile()中的断言错误? [英] Assertion error in CRT calling _osfile() in VS 2008?
问题描述
我有一个已经工作了很长时间的C ++代码库。代码库是一个遗留的VS 2003项目集,我最近迁移到VS 2008。迁移似乎是成功的,结果程序构建并运行。
我重新安装了我的操作系统和所有应用程序在一个新的驱动器,现在当我试图调试程序在调试器内,我收到一个断言错误在CRT的 chsize
(真的, _chsize_s
)。
FILE * testfile = fopen(P:\\_Dan\\ \\\local\\foogoo.txt,w);
int filehandle = fileno(testfile);
chsize(filehandle,0);
fwrite(goohoo,1,6,testfile);
fclose(testfile);
调试断言发生在 chsize
,在CRT的源代码文件chsize.c中,在下面一行:
_VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE((_ osfile(filedes)& FOPEN ),EBADF);
...其中归档
匹配 filehandle
。
我认为这个问题可能是由于没有在新系统上安装旧版本的VS VS 2008),因为一些第三方库需要VS 8.0可重新分发 - 即使在老系统上似乎正在建设和运行VS 2008年。我因此安装VS 2005(而不是2003年)。
*
/ em>更新 - 此问题与 chsize
无关。请参阅下面的答案。问题已解决 - 与 chsize
。选择用于代码生成的c运行时库的链接模型被设置为主项目的多线程调试(/ MTd),但是被链接的解决方案中的所有项目的多线程调试DLL(/ MDd)至。更改为/ MDd解决了问题。
我熟悉这些链接问题,通常小心设置它们,但是因为这是一个工作项目的升级一个早期版本的Visual Studio没有更改,我没有想到看这条路。我没有调查如何或为什么设置被改变(或者即使它是设置为这种方式在以前的版本,但没有导致问题)。
I have a C++ code base that has been working for a long time. The code base was a legacy VS 2003 set of projects that I recently migrated to VS 2008. The migration seemed to be successful in that the resulting program built, and run.
I reinstalled my OS and all applications on a fresh drive, and now when I attempt to debug the program within the debugger, I receive an assertion error inside the CRT's chsize
(really, _chsize_s
). Specifically (cropped to essentials, ignoring safety checks):
FILE * testfile = fopen("P:\\_Dan\\local\\foogoo.txt", "w");
int filehandle = fileno(testfile);
chsize(filehandle, 0);
fwrite("goohoo", 1, 6, testfile);
fclose(testfile);
The debug assertion occurs within chsize
- specifically, within the CRT's source code file chsize.c, at the following line:
_VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE((_osfile(filedes) & FOPEN), EBADF);
... where filedes
matches filehandle
.
I thought possibly the problem might result from not having an older version of VS installed on the new system (only VS 2008), because some 3rd-party libraries require VS 8.0 redistributable - even though on the old system things seemed to be building and running just fine using VS 2008. I therefore installed VS 2005 (not 2003). However, the problem continues to occur.
Any suggestions would be immensely welcome.
* Update - The issue is unrelated to chsize
. See my answer below.
The issue is resolved - and unrelated to chsize
. The linking model to the c-runtime libraries chosen for code generation was set to multi-threaded debug (/MTd) for the main project, but multi-threaded debug DLL (/MDd) for all of the projects in the solution that it linked to. Changing to /MDd resolved the issue.
I am familiar with these linking issues and am generally careful to set them properly, but because this was an upgrade of a working project from an earlier version of Visual Studio with no changes, I did not think to look down this road. I did not investigate how or why the setting was changed (or even if it was set this way in the previous version but did not cause problems).
这篇关于VS 2008中CRT调用_osfile()中的断言错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!