문제

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.

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top