Learn C++ 5: Inline Function
I got the error message below when compiling my project. At the beginning, I had no idea what was going on. I only define the function load_engine
once in the header file, and there is no definition elsewhere.
/usr/bin/ld: CMakeFiles/main.dir/src/trt.cpp.o: in function `load_engine()':
trt.cpp:(.text+0x131): multiple definition of `load_engine()';
CMakeFiles/main.dir/src/main.cpp.o:main.cpp:(.text+0x0): first defined here
It looks like this in the header file
struct infer_params
{
std::string weights_file; // currently supports only uff file
int batch_size;
std::string save_engine;
std::string load_engine;
};
bool load_engine(){
// do something....
}
load_engine
was defined with a string in the struct, and then load_engine
was defined with a function. I could change the namings or use inline
when define load_engine
at the second time. As an inline function is a function defined in C++ that is expanded in place at each point in your code where it is called, rather than being called through the usual function call mechanism.
Enjoy Reading This Article?
Here are some more articles you might like to read next: