c++ - 错误:包含时“带有 C 链接的模板”和“带有 C 链接的模板特化”
问题描述
问题背景:
在ProjectA中,agent_multi_threading.hpp
包含在agent.h
.
在ProjectB中,我试图包含agent.h
在processing_core.h
.
ProjectA是用 C 编写的,而ProjectB是用 C++ 编写的。
下面的代码显示了包括的层次结构:
/* File: agent_multi_threading.hpp ProjectA */
#ifdef __cplusplus
#include <atomic>
using namespace std;
#else
/* File: agent.h in ProjectA */
#include "agent_multi_threading.hpp"
/* File: processing_core.h ProjectB */
extern "C" {
#include "agent.h"
}
错误信息:
In file included from /<compiler_path>/gnu/gcc/8.2.0/rhesys/include/c++/8.2.0/atomic:41,
from /<dir_path>/ProjectB/src/agent_multi_threading.hpp:30,
from /<dir_path>/ProjectB/src/agent.h:10,
from /<dir_path>/ProjectA/src/processing_core.cpp:5:
/<compiler_path>/gnu/gcc/8.2.0/rhesys/include/c++/8.2.0/bits/atomic_base.h:109:3: error: template with C linkage
template<typename _Tp>
^~~~~~~~
/<dir_path>/ProjectA/src/processing_core.cpp:5:1: note: 'extern "C"' linkage started here
extern "C" {
^~~~~~~~~~
from /<dir_path>/ProjectB/src/agent_multi_threading.hpp:30,
from /<dir_path>/ProjectB/src/agent.h:10,
from /<dir_path>/ProjectA/src/processing_core.cpp:5:
/<compiler_path>/gnu/gcc/8.2.0/rhesys/include/c++/8.2.0/atomic:62:3: error: template specialization with C linkage
template<>
^~~~~~~~
Q1。“带有 C 链接的模板”和“带有 C 链接的模板特化”是什么意思?
Q2。为什么在我的代码中会发生这种情况?
解决方案
推荐阅读
- php - 未定义索引:Laravel 中针对少数用户的 HTTP_USER_AGENT
- c# - C# 项目属性的文档:`
严格的 ` - reactjs - 如何在另一个 wordpress 网站中显示反应网站记录的用户详细信息
- oauth-2.0 - 如何申请领英邀请、人员和连接 API
- reactjs - 无法集成 styleguidist 以生成文档
- python - numpy 有一个名为 math 的模块吗?
- reactjs - 如何在反应中使用 Hooks 更新设备宽度的状态
- javascript - 页面上特定元素上的滚动指示器
- spring-cloud-deployer-kubernetes - 使用 containerCommand 属性执行多行命令
- pseudocode - TSP 的大 O 时间复杂度