LNK2019 和 LNK1120 具有外部文件中的函数
我已将一些函数从一个源文件取出到另一个文件中,因为我想在其他文件中也使用它们。当前结构如下
utils/extFuncs.h
#ifndef _extFuncs_h
#define _extFuncs_h
inline int someFunction (float v);
#endif
utils/extFuncs.cpp
#include "utils/extFuncs.h"
inline int someFunction (float v) {
return 42;
}
foo/bar.h
#ifndef _bar_h
#define _bar_h
#include "utils/extFuncs.h"
class Bar {
public:
Bar (float x);
};
#endif
foo/bar.cpp问题
#include "foo/bar.h"
Bar::Bar (float x) {
int y = someFunction(x);
}
是,当我尝试编译它时,链接器抱怨并说符号 someFunction
无法解析。
I have taken out some functions from a source file into another since I want to use them also in other files. The current structure is as follows
utils/extFuncs.h
#ifndef _extFuncs_h
#define _extFuncs_h
inline int someFunction (float v);
#endif
utils/extFuncs.cpp
#include "utils/extFuncs.h"
inline int someFunction (float v) {
return 42;
}
foo/bar.h
#ifndef _bar_h
#define _bar_h
#include "utils/extFuncs.h"
class Bar {
public:
Bar (float x);
};
#endif
foo/bar.cpp
#include "foo/bar.h"
Bar::Bar (float x) {
int y = someFunction(x);
}
Problem is, that when I try to compile this, the linker complains and says that the symbol someFunction
could not be resolved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
someFunction
被声明为内联
,因此它必须在头文件中定义:someFunction
is declaredinline
, so it must be defined in your header file:您是否尝试过添加 extFunction.h & extFunction.cpp 到您的项目工作区中吗?
Have you tried to add the extFunction.h & extFunction.cpp into your project workspace?