The simple C++ code I wrote below got compile error
“undefined reference to ‘featureExtract()'” (using codeblocks under windows),
in FeaureExtract.h
#ifndef FEATUREEXTRACT_H_INCLUDED
#define FEATUREEXTRACT_H_INCLUDED
extern void featureExtract();
#endif // FEATUREEXTRACT_H_INCLUDED
in FeatureExtract.cpp
#include "FeatureExtract.h"
void featureExtract()
{
some code
}
in main.cpp
#include "FeatureExtract.h"
int main()
{
featureExtract();
}
I have searched the SO using keyword “C++ undefined reference to” and read tens of entries (many are to class or under Linux), but I could not get my own problem addressed (I don’t know why).
Thanks for any hint~
Before solving this problem, I have no choice but put all the staff in FeatureExtract.h, it works, but it seems not good. This post ( Why have header files and .cpp files in C++? ) explains the main merit of .h files is “separating the interface from the implementation”, I wonder if putting all interface and implementation in .h files will have other effects?
Thank you~
It looks like you aren’t linking both object files together into your final binary. Unfortunately I’m not familiar with codeblocks, but make sure all the
.cppfiles are added to your project.Another less likely possibility is that somehow the name decoration is different between the two cpp files. Make sure you’re using C++ to compile both files and that one doesn’t compile as C code for example.