【问题标题】:<algorithm> won't compile on Dev C++ compiler<algorithm> 不会在 Dev C++ 编译器上编译
【发布时间】:2011-10-08 00:24:00
【问题描述】:

我正在尝试使用 Dev_C++ 4.9.9.2 编译器移植一些代码,但我无法让它像在

中那样识别标准算法模板
#ifdef __cplusplus
extern "C" {
#endif

#include <algorithm>
#include <string>
using namespace std;

每当我尝试编译时,都会收到大量错误消息,其中大多数是“带有 C 链接的模板”。我究竟做错了什么?我需要在编译器上调整一些设置吗?

技术规格 - 我在 Oracle VirtualBox 上的 Windows XP SP3 上运行编译器,而后者又在 Ubuntu 10.10 AMD64 主机上。

【问题讨论】:

  • 原始代码语言是什么? C?您可能需要将#endif 放在最后...。自从我研究 C++ 以来已经有一段时间了。另外,你没有另一个花括号....
  • 次要问题:#include &lt;algorithm&gt; 如果不是 C++ 环境,则无论如何都会失败。因此,在extern "C" { 周围使用#ifdef __cplusplus 守卫几乎没有意义

标签: templates compiler-construction linker-errors dev-c++ stl-algorithm


【解决方案1】:

答案似乎已经在一个现已被删除的答案中给出:将包含移到 extern "C" { 大括号之外

using namespace std ;
#include <algorithm>
#include <string>

#ifdef __cplusplus
extern "C" {
#endif

这样编译没有错误消息。

【讨论】:

    猜你喜欢
    • 2011-01-10
    • 2010-12-18
    • 2020-08-28
    • 1970-01-01
    • 2011-05-16
    • 2019-07-20
    • 1970-01-01
    • 2012-07-23
    • 2021-10-05
    相关资源
    最近更新 更多