Message "error: use of undeclared identifier 'assert'"
Message "error: use of undeclared identifier 'assert'"
我有一段代码包含一些 Boost headers。编译后我收到类似
的错误
/usr/local/include/boost/smart_ptr/shared_ptr.hpp:1041:9: error: use of undeclared identifier 'assert'
BOOST_ASSERT( deleter_.use_count() <= 1 );
^
/usr/local/include/boost/assert.hpp:60:29: note: expanded from macro 'BOOST_ASSERT'
# define BOOST_ASSERT(expr) assert(expr)
^
然而,这些错误仅发生在 Windows 和 macOS 上。
在提升 headers 无效之前明确包含 <cassert>
或 <assert.h>
。
事实证明,我的 include-path 中有一个名为 Assert.h
的文件(我的自定义文件)。在 Windows 和 macOS 使用的 case-insensitive 文件系统上,这将隐藏实际定义 assert
宏的原始 assert.h
header。
因此,解决方案只是重命名我的 assert-header 文件。
(感谢 [Compilation Error] error: use of undeclared identifier 'assert' #15,我找到了解决方案。)
您需要 #include <cassert>
引入 assert
实施。
相应地定义或不定义NDEBUG
是你的工作。
我很惊讶 Boost 没有为您做这些 - 您是否正确使用了 Boost 文件(即包括您应该使用的文件)?
我有一段代码包含一些 Boost headers。编译后我收到类似
的错误/usr/local/include/boost/smart_ptr/shared_ptr.hpp:1041:9: error: use of undeclared identifier 'assert'
BOOST_ASSERT( deleter_.use_count() <= 1 );
^
/usr/local/include/boost/assert.hpp:60:29: note: expanded from macro 'BOOST_ASSERT'
# define BOOST_ASSERT(expr) assert(expr)
^
然而,这些错误仅发生在 Windows 和 macOS 上。
在提升 headers 无效之前明确包含 <cassert>
或 <assert.h>
。
事实证明,我的 include-path 中有一个名为 Assert.h
的文件(我的自定义文件)。在 Windows 和 macOS 使用的 case-insensitive 文件系统上,这将隐藏实际定义 assert
宏的原始 assert.h
header。
因此,解决方案只是重命名我的 assert-header 文件。
(感谢 [Compilation Error] error: use of undeclared identifier 'assert' #15,我找到了解决方案。)
您需要 #include <cassert>
引入 assert
实施。
相应地定义或不定义NDEBUG
是你的工作。
我很惊讶 Boost 没有为您做这些 - 您是否正确使用了 Boost 文件(即包括您应该使用的文件)?