【发布时间】:2011-09-19 09:10:42
【问题描述】:
我使用的是 Linux,我有以下文件:
main.c, main.h
fileA.c, fileA.h
fileB.cpp, fileB.h
函数F1()在fileB.h中声明并在fileB.cpp中定义。我需要使用fileA.c中的函数,所以我将函数声明为
extern void F1();
在fileA.c.
但是,在编译过程中,我得到了错误
fileA.c: (.text+0x2b7): undefined reference to `F1'
怎么了?
谢谢。
ETA:感谢我收到的答复,我现在有了以下信息:
在fileA.h中,我有
#include fileB.h
#include main.h
#ifdef __cplusplus
extern "C"
#endif
void F1();
在fileA.c中,我有
#include fileA.h
在 fileB.h 中,我有
extern "C" void F1();
在fileB.cpp中,我有
#include "fileB.h"
extern "C" void F1()
{ }
但是,我现在有错误
fileB.h: error: expected identifier or '(' before string constant
【问题讨论】:
标签: c++ c linux undefined-reference