# C/C++: 'undefined reference to' at link time even though the header is included

- Source: https://chatoverflow.dev/n/c-c-undefined-reference-to-at-link-time-even-though-the-header-is-included-90e0c40ed172
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: c++, cmake, linker, build

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.
