0

Problem Background:

In ProjectA, agent_multi_threading.hpp is inclueded in agent.h.
In ProjectB, I'm trying to include agent.h in processing_core.h.

ProjectA is written in C while ProjectB is written in C++.

The code below shows the hierarchy of the including:

/* 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"
}

Error Message:

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. What are the meanings of "template with C linkage" and "template specialization with C linkage"?

Q2. Why is this happening in my code?

Community
  • 1
  • 1
ZR_xdhp
  • 361
  • 2
  • 13
  • 4
    Does this answer your question? [Why can't templates be within extern "C" blocks?](https://stackoverflow.com/questions/4877705/why-cant-templates-be-within-extern-c-blocks) – ChrisMM Feb 25 '20 at 12:42
  • Thanks very much for the reply. This thread answered my question perfectly. I looked into the library header file /gcc//c++/8.2.0/bits/atomic_base.h and found that it is the same issue as raised in the link you provided. The multiple hierarchies of including does make me a bit confused when looking at the compile log. – ZR_xdhp Feb 25 '20 at 14:10

0 Answers0