【问题标题】:#define _AFX_NO_DEBUG_CRT causes a stream of compilation errors#define _AFX_NO_DEBUG_CRT 导致编译错误流
【发布时间】:2009-08-12 11:26:20
【问题描述】:

我在 Visual Studio 2008 下有一个 MFC C++ 项目编译器。

我在 #include 之前的 stdafx.h 中添加了一个 _AFX_NO_DEBUG_CRT 以避免 MFC 提供的所有调试新和删除(我希望提供我自己的以实现更好的跨平台兼容性)。

但是,当我这样做时,我会收到如下错误流:

>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : '__asm'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ')' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before '{'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before 'constant'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2143: syntax error : missing ';' before ','
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxtls_.h(62) : error C2059: syntax error : ')'
1

我“认为”它可能与 __asm int 3 调用有关,但我不能确定。以前有人遇到过这个问题吗?如果是这样,你是如何解决的?我是否坚持使用 MFC 的内存跟踪?我真的不希望因为它会让我的库少很多跨平台:(

任何帮助将不胜感激!

【问题讨论】:

    标签: c++ visual-studio-2008 mfc


    【解决方案1】:

    我想出了一种方法,它涉及使用 /FORCE:MULTIPLE 命令行来强制它使用我的而不是 MFC。这一切似乎都很好。我现在甚至可以跟踪不属于我的函数执行的“mallocs”和“new”s :)

    如果有人有更好的解决方案,请发布它们,但现在这似乎解决了我的问题 :)

    【讨论】:

    • 仍然没有回答为什么你的“跨平台”库链接 MFC 的问题?
    • 您介意解释一下您是如何解决编译问题的吗?我遇到的编译错误与您完全相同 - 您是否删除了 #define _AFX_NO_DEBUG_CRT?
    • 我确实删除了我的定义,并看到与新的力倍数的新定义相关的所有问题都解决了问题。 Fat Elvis 的帖子解释了为什么这样的定义不好(tm)。
    【解决方案2】:

    我过去曾尝试弄乱_AFX_NO_DAO_SUPPORT 宏,但它所做的只是导致无休止的崩溃。我最终看到了这篇文章:

    PRB: Problems Occur When Defining _AFX_NO_XXX

    它没有具体列出您尝试使用的那个,但它可能仍然适用。

    【讨论】:

    • 酷绝对值得了解,但我尝试使用的定义似乎不会影响 VTABLES。它似乎只用于一堆服务功能,而不是在类中使用。
    【解决方案3】:

    尝试将#define 放在项目编译选项中,而不是放在 stdafx.h 的顶部。

    如果您使用 MFC,您如何期望构建跨平台库?避免 new 和 delete 重载不会有什么不同。

    此外,您永远不会编写像 MFC 提供的那样可靠和完整的分配跟踪器。 YAGNI,专注于开发您的实际应用程序。

    【讨论】:

    • 我的库是跨平台的,不是 MFC 部分。
    • 另外值得注意的是,将其放入项目定义中也不起作用。
    • 如果您的库是跨平台的,为什么需要 MFC #define?
    猜你喜欢
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 2015-09-12
    • 2021-05-17
    • 2015-11-19
    • 2015-10-03
    相关资源
    最近更新 更多