Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一个 C 代码,比如“test.c”,并从中调用一些 C++ 函数。
我有一个头文件 header.h,其中定义了函数,还有一个 C++ 文件,其中定义了函数。
我无法弄清楚编译命令以及如何使用该extern命令。有人可以澄清一下吗?
extern
我想编写一个 C 代码,比如“test.c”从中调用一些 C++ 函数。
在你的标题中尝试这样的事情:
#ifdef __cplusplus extern "C" { #endif void foo (void); #ifdef __cplusplus }; #endif
然后foo()在你的 .cpp 文件中实现。确保您的 .cpp 文件也包含标题。
foo()