views:

106

answers:

3

My linker is reporting an error as follows:

unresolved external symbol "unsigned char __fastcall BD_CLC(int,int)"...

But I maintain that all references to this function, as well as the definition of the function are of the form:

__forceinline UBYTE BD_CLC(int swap,int elem);

I even did a compilation with "Generate preprocessed file" set and went through the output. In every file where BD_CLC was used, the function was declared as

__forceinline UBYTE BD_CLC(int swap,int elem);

and of course the actual function definition was declared as

__forceinline UBYTE BD_CLC(int swap,int elem) { ... }

Any ideas?

+1  A: 

Since you've declared the function __forceinline, you need to make sure the definition - not just the declaration - is visible everywhere the function is called.

moonshadow
In every file that the function is called, the prototype __forceinline UBYTE BD_CLC(int swap,int elem); appears before the function is called. This is according to the ".i" files produced by the preprocessor.
Mick
Not just the prototype, the body has to be visible too. With __forceinline, you're telling the compiler to slap the body verbatim into the generated code wherever the function is called, but if it can't see the body it can't do that, so it generates a call; but because you've used __forceinline, code for the body is never separately generated and so the target of the call cannot be resolved and you get a link error.
moonshadow
so should putting the definition in the header file withthe declaration do the trick? Then everywhere it's included the body should be visible too no?
Neil
@Neil: yup. Except that makes the header less readable, so one might prefer to place the definitions of inline functions in a separate file and #include that at the bottom of the header after all the declarations.
moonshadow
Program now compiled and working. Thanks for your help.
Mick
+1  A: 

I think you may have to turn off the /GR "Calling Convention" compiler option. Perhaps the __fastcall is causing the Linker error.

/Gr specifies the __fastcall calling convention for all functions except C++ member sfunctions and functions marked __cdecl or __stdcall. All __fastcall functions must have prototypes.

Neil
But the program is speed critical - I don't want to turn off __fastcall.
Mick
are you sure it is turned on for every compilation unit then?
Neil
@neil, yes - its set in the project properties.
Mick
A: 

I would try to remove the __forceinline attribute.

RED SOFT ADAIR