C++ MySQL ++中的“'assert'未在此范围内声明”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2909059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"'assert’ was not declared in this scope" in MySQL++
提问by Anonymous
I'm compiling a project in XCode where MySQL++ in included and linked to. For some reason, I keep getting the following compiler error:
我正在 XCode 中编译一个项目,其中包含并链接到 MySQL++。出于某种原因,我不断收到以下编译器错误:
'assert' was not declared in this scope
'assert' 未在此范围内声明
originating from cpool.h, a header file that's part of MySQL++. Does anyone know why this is being triggered?
源自 cpool.h,这是 MySQL++ 的一部分的头文件。有谁知道为什么会触发这个?
EDIT: For reference, MySQL++ was installed via Macports.
编辑:作为参考,MySQL++ 是通过 Macports 安装的。
回答by Troubadour
The most obvious answer would be that "assert.h" is not being included or is not being found in your include path. Another explanation is that the assert macro has been undefined at some point after the header was included.
最明显的答案是“assert.h”未包含在包含路径中或未在包含路径中找到。另一种解释是断言宏在包含标头后的某个时刻未定义。
Edit: Since you say that assert.h is included, and we'll assume for the moment that it's being found since it's a standard header, then that leaves us with the last possibility I stated above i.e. that the macro has been undefined.
编辑:既然你说包含了 assert.h,并且我们暂时假设它被找到,因为它是标准头文件,那么这给我们留下了我上面提到的最后一种可能性,即宏尚未定义。
Since cpool.h itself will not be doing this it must be the case that assert.h is included earlier either by yourself or indirectly by another 3rd party header and the undefining happening between this and your inclusion of cpool.h. This can easily be tested by moving your cpool.h include to the top of your file.
由于 cpool.h 本身不会执行此操作,因此必须是 assert.h 之前由您自己或由另一个 3rd 方标头间接包含的情况,以及在此与您包含 cpool.h 之间发生的不确定性。这可以通过将 cpool.h 包含到文件顶部轻松测试。
回答by MBI
In c++ adding cassert header should fix your problem.
在 C++ 中,添加 cassert 标头应该可以解决您的问题。
#include <cassert>
回答by Greg Prisament
It could be that another library in your include path has a different "assert.h" file, and you are unknowingly including that one instead of the system's standard <assert.h>.
可能是包含路径中的另一个库具有不同的“assert.h”文件,而您在不知不觉中包含了该文件而不是系统的标准 <assert.h>。
I ran into this issue when writing an application that uses gstreamer on Mac OSX. It turns out that gstreamer's include directory (/Library/Frameworks/GStreamer.framework/Headers) includes a file "assert.h", which is non-standard and an unsuitable replacement for the real assert.h. When I added -I/Library/Frameworks/GStreamer.frameworks/Headers to my compilation command, suddenly my sources, which just said "#include <assert.h>" where including the gstreamer version. This caused my compilation to fail with the same error you were getting.
我在 Mac OSX 上编写使用 gstreamer 的应用程序时遇到了这个问题。事实证明,gstreamer 的包含目录(/Library/Frameworks/GStreamer.framework/Headers)包含一个文件“assert.h”,它是非标准的,不适合替代真正的 assert.h。当我将 -I/Library/Frameworks/GStreamer.frameworks/Headers 添加到我的编译命令时,突然出现了我的来源,它只是说“#include <assert.h>”,其中包括 gstreamer 版本。这导致我的编译失败,并出现与您相同的错误。