c++ - 尝试构建 C++ 程序时收到错误消息 "Template with C linkage"

标签 c++ gcc codeblocks mingw32

<分区>

我正在尝试使用 CodeBlocks 和 Mingw 构建一个 C++ 程序,我收到来自 STL 库文件(例如 STL_uninitalized.h 和 vector.cc)的错误

|=== 构建:全部在 MinervaSegs 中(编译器:GNU GCC 编译器)===| C:\PROGRA~2\CODEBL~1\MinGW\lib\gcc\mingw32\4.9.2\include\c++\bits\STL_uninitialized.h|63|error: 带有 C 链接的模板

最佳答案

您可能正在使用范围 extern "C" 表示法并在该范围内包含 C++ 代码。例如:

#ifdef __cplusplus
extern "C" {
#endif

#include <vector> // could generate this error

template <typename T> // would also generate this error
struct MyExample
{
    T data;
};

#ifdef __cplusplus
}  // end extern "C"
#endif

您通常应该完全避免包含在 extern "C" 区域中,因为这会导致对原本相同的符号进行多次声明。

当与不让 C++ 感知的 C 代码交互时,有一些特定的异常(exception)情况 - 但买者自负。

关于c++ - 尝试构建 C++ 程序时收到错误消息 "Template with C linkage",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38503934/

相关文章:

c++ - qt: QInputDialog::getText 不工作

c++ - 在 C++ 中查找 2 个数字的比率

C++:如何挑选出 vector 中最后四分之一的元素?

c - 使用 GCC 在 C 中打印 printf long long int?

c++ - 继承问题 : Using header files and default constructor of the base class in the derived class

c++ - C++ 中线程管理和工作分配的可能框架/想法

c - Libtool 为对象添加前缀,但 gcov 要求它们没有前缀

c++ - Bool 永远不会为 NULL [-Waddress]

Code::Blocks 中单个文件的 c99 模式

c - 对 'addVectors(Vector,Vector)' 的 undefined reference