C++ Inlining Class Methods Causes Undefined Reference

C++ inlining class methods causes undefined reference

The body of an inline function needs to be in the header so that the compiler can actually substitute it wherever required. See this: How do you tell the compiler to make a member function inline?

undefined reference when calling inline function

According to the manual, passing -std=gnu11 enables C99 instead of GNU inline semantics.

This means inline, static inline and extern inline all behave differently. In particular, inline expects an external definition in a separate translation unit (which you can provide without duplicating the definition - see this answer).

Undefined symbol error when use inline methods in C++

An inline function needs it's definition to be available in the file that is calling that function.

So if You define it in one cpp file and try to call it in a second cpp file, then it will not be found.

What You need to do is move this definition into the h file. (just cut & paste it after the class definition).

Or as @einpoklum has noticed, if You don't need it, remove the inline from all the definitions.

Error undefined reference to to some not-inline methods of a library

It seems the problem is caused by a broken cmake list. After several changes i can compile both now. However this looks realy strange to me, since all files existed in the cmakelists.



Related Topics



Leave a reply



Submit