【发布时间】:2017-05-27 12:34:44
【问题描述】:
我正在写论文,但在 C 代码中使用 C++ 函数时遇到问题。我搜索了解决方案,发现了很多,但无论如何都没有用。请再给我解释一遍。
为了快点,我有类似下面的内容,在gcc main.c -o main 之后我得到undefined reference to 'cppfun'
cpp.h:
#pragma once
#ifdef __cplusplus
extern "C" {
#endi
void cppfun();
#ifdef __cplusplus
}
#endif
cpp.cpp:
#include <stdio.h>
#include "cpp.h"
void cppfun()
{
printf("cpp_fun");
}
main.c:
#include <stdio.h>
#indlude "cpp.h"
int main(int argc, char *argv[])
{
cppfun();
return 0;
}
【问题讨论】: