编译 C++ 代码时如何解决一些版本控制问题?

Posted

技术标签:

【中文标题】编译 C++ 代码时如何解决一些版本控制问题?【英文标题】:how do I fix some versioning issue when compiling C++ code? 【发布时间】:2012-03-26 18:29:08 【问题描述】:

我正在尝试在 Linux 上编译 http://sourceforge.net/projects/desr/files/Release/desr-0.9.tgz/download 的文件。

当我运行 ./configure 时,一切都很顺利,直到我输入 make。 然后我得到以下错误:

In file included from ./string.h:33,
                 from htmlTokenizer.cpp:24:
/usr/include/c++/4.4/cstring:76: error: ‘::memchr’ has not been declared
/usr/include/c++/4.4/cstring:77: error: ‘::memcmp’ has not been declared
/usr/include/c++/4.4/cstring:78: error: ‘::memcpy’ has not been declared
/usr/include/c++/4.4/cstring:79: error: ‘::memmove’ has not been declared
/usr/include/c++/4.4/cstring:80: error: ‘::memset’ has not been declared
/usr/include/c++/4.4/cstring:81: error: ‘::strcat’ has not been declared
/usr/include/c++/4.4/cstring:82: error: ‘::strcmp’ has not been declared
/usr/include/c++/4.4/cstring:83: error: ‘::strcoll’ has not been declared
/usr/include/c++/4.4/cstring:84: error: ‘::strcpy’ has not been declared
/usr/include/c++/4.4/cstring:85: error: ‘::strcspn’ has not been declared
/usr/include/c++/4.4/cstring:86: error: ‘::strerror’ has not been declared
/usr/include/c++/4.4/cstring:87: error: ‘::strlen’ has not been declared
/usr/include/c++/4.4/cstring:88: error: ‘::strncat’ has not been declared
/usr/include/c++/4.4/cstring:89: error: ‘::strncmp’ has not been declared
/usr/include/c++/4.4/cstring:90: error: ‘::strncpy’ has not been declared
/usr/include/c++/4.4/cstring:91: error: ‘::strspn’ has not been declared
/usr/include/c++/4.4/cstring:92: error: ‘::strtok’ has not been declared
/usr/include/c++/4.4/cstring:93: error: ‘::strxfrm’ has not been declared
/usr/include/c++/4.4/cstring:94: error: ‘::strchr’ has not been declared
/usr/include/c++/4.4/cstring:95: error: ‘::strpbrk’ has not been declared
/usr/include/c++/4.4/cstring:96: error: ‘::strrchr’ has not been declared
/usr/include/c++/4.4/cstring:97: error: ‘::strstr’ has not been declared

任何想法可能是什么问题?

这里是 g++ --version:

g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

【问题讨论】:

【参考方案1】:

有的时候

 #include <cstring> 

g++ 编译器应该将它本身包含的声明放入 std:: 和全局命名空间中。出于某种原因,它看起来好像没有这样做。尝试用 std::strcpy 替换一个 strcpy 实例。

【讨论】:

Makefile 可能会提供一个编译器标志,以避免包含标准包含路径。【参考方案2】:

我遇到了类似的问题。就我而言,头文件包含的顺序如下

#include <string> // for string class
#include <cstring> // for memcpy()

有了这个,我遇到了你在 gcc 4.6.3 中提到的上述错误。

切换包含工作的顺序..

【讨论】:

【参考方案3】:

此问题的一个可能原因是您设法在命名空间块内的某个地方获得了 #include &lt;cstring&gt;

这会导致为包含保护设置#define,阻止您在其他任何地方重新导入它,但同时将所有符号加载到您的命名空间而不是它们所属的全局范围内。

当我尝试将内联模板定义与其声明放在单独的文件中时,有时会犯此错误。

【讨论】:

以上是关于编译 C++ 代码时如何解决一些版本控制问题?的主要内容,如果未能解决你的问题,请参考以下文章

如何在vs代码中编译c++?

如何在 c++ Autotools 项目中使用不同版本的 g++ 进行编译

如何在Visual Studio中选择C++和C#的编译器版本

如何将 c、c++ 和 python 代码编译为“Released/Final”版本? [关闭]

如何在我自己的代码中使用 Visual C++ 在不运行静态代码分析的情况下导致 SAL 编译器警告

如何验证编译时在 msvc 2010 c++ 项目中是不是正确设置了编译器选项?