Trying to put inline functions in external file within project, and getting below errors.
If I remove "__forceinline", then all is well.
If I have the inline function in main cpp file and not in header, it is fine also.
Is there a procedure to deal with this?


__forceinline __int64 Parse(const unsigned char *);


__forceinline __int64 Parse(const unsigned char * parsearray){
//nothing special
return 0;

error LNK2001: unresolved external symbol "__int64 __cdecl Parse(const unsigned char *)"
fatal error LNK1120: 1 unresolved externals

I am aware that __forceinline does not mean the compiler (vs2010) will inline it.

Recommended Answers

All 3 Replies

inline functions can't be declared in a *.cpp file and expect it to be inlined in other *.cpp files. Put the entire code in the file.h header file so that the compiler can duplicate the code each time the function is called. This is consistent with the use of _inline for c++ class methods, where you write the entire function in the header file.

For the compiler to be able to inline a function, it must see its definition (implementation). This means you cannot do the classic "declaration in header" / "definition in cpp file" paradigm. The definition must be in the header file. Marking the function as inline or __forceinline tells the compiler that this is what you will do, thus making the functions candidates for inlining.

Thanks for your time and explanation.
Of course it is sage advice and works as expected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.