I\'m trying to build a CMake project that calls C code from C++, and I\'m getting undefined symbols, even though I\'m (AFAIK) properly using \"extern C\".
CMakeLists.txt
extern "C"
is C++ syntax. Your header lib.h therefore cannot be used from C. If you change it as follows it can be used from C++ and C as well.
#ifndef LIB_H_HEADER
#define LIB_H_HEADER
#ifdef __cplusplus
extern "C"
{
#endif
int printit();
#ifdef __cplusplus
}
#endif
#endif /* LIB_H_HEADER */
As you have both C and CXX sources your project call should enable C as well project(CTest LANGUAGES C CXX)
in your CMakeLists.txt.