Pergunta

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.

Foi útil?

Solução

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

Outras dicas

Have you tried to add the extFunction.h & extFunction.cpp into your project workspace?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top