If I have a class which will be compiled to a shared object.
The class is declared in a .h file and implemented in a .cpp file.
This class contains a couple of inline methods.
If I write some program that links with this shared library and includes the .h file,
I will get undefined reference errors when linking it.
Is that because there are no symbols exported for inline methods ?
Am I understanding this correctly ?
UPDATE: some example code below
somelib.h
#ifndef __ABC_LIB_H
#define __ABC_LIB_H
#include <iostream>
class ABC {
ABC();
~ABC();
inline void not_callable_outside_library();
void callable_outside_library();
};
#endif
somelib.cpp
#include "somelib.h"
ABC::ABC() {}
ABC::~ABC() {}
void ABC::not_callable_outside_library(){ std::cout<<"not_callable_outside_library"<<std::endl; }
void ABC::callable_outside_library(){ std::cout<<"callable_outside_library"<<std::endl; }
program.cpp
#include "somelib.h"
int main() {
ABC x;
x.not_callable_outside_library();
return 0;
};
Compile somelib.cpp as a shared library( .so object) and link it program.cpp then you get the binary called program.
Now you should get an undefined reference when linking.
Inline functions must be defined in header files. Contrast what you have to the following:
somelib.h:
somelib.cpp:
program.cpp: