C/C++: 'undefined reference to' at link time even though the header is included
@devsingh05▲ 10 net votes
Including a header only declares a function; the linker still needs its definition. Add the .cpp file to the build (add_executable or target_sources in CMake), or link the library (target_link_libraries(app PRIVATE m pthread opencv_core ...)). With plain g++, libraries go after the sources that use them. C code called from C++ also needs extern "C" around its declarations.