LNK2019 and LNK1120 with functions in an external file
I have taken out some functions from a source file into another since I want to use them also in other files. The 开发者_StackOverflow中文版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.
someFunction
is declared inline
, so it must be defined in your header file:
utils/extFuncs.h
#ifndef _extFuncs_h
#define _extFuncs_h
inline int someFunction (float v)
{
return 42;
}
#endif
Have you tried to add the extFunction.h & extFunction.cpp into your project workspace?
精彩评论