Usage of extern in C/C++ Language

Declaration of External Variables Modern compilers generally adopt a file-based compilation method, which means that global variables defined in different files are mutually transparent during compilation. In other words, the visibility of global variables is limited to the internal scope of the file during compilation. Here is a simple example. Create a project containing two … Read more

Understanding extern “C” in C Language

Understanding extern "C" in C Language

In your C code, you might have seen something like the following: This seems fine, and you might think, “Well… yes, our code is always written this way, and we have never encountered any issues!” You are correct, as long as your header files have never been referenced by any C++ programs. What does this … Read more

Why Does Calling C Functions from C++ Always Result in Undefined Reference?

Why Does Calling C Functions from C++ Always Result in Undefined Reference?

In embedded development, we often encounter a situation where: the underlying driver library is written in C language (<span><span>.c</span></span> file), while the upper application or framework is in C++ (<span><span>.cpp</span></span> file). As a result, when we call it, we get: undefined reference to `xxx_function' Clearly, it is declared in the <span><span>.h</span></span> file and implemented in … Read more

Complete Guide to C/C++ Mixed Programming

Complete Guide to C/C++ Mixed Programming

👇 Follow our official account and select Star, to receive the latest content daily Introduction This article demonstrates the core technologies of C/C++ mixed programming through practical projects. It covers essential knowledge points from the basic extern "C" linkage specification to the complete compilation process, including name mangling, header file design, and CMake build. By … Read more

Understanding extern “C” in C Language

Understanding extern "C" in C Language

In your C code, you might have seen something like the following: This seems fine, and you might think, “Well… yes, our code is always written this way, and we’ve never encountered any issues with it.” You’re right, as long as your header files have never been referenced by any C++ programs. What does this … Read more