Hello C++ professionals, I am getting an error below. I have searched online for this solution, but I cannot see where the problem is since I added the header file accordingly to the .cpp files. Can you help me please.
Error is:
CMakeFiles\untitled23.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/CLionProjects/untitled23/main.cpp:8: undefined reference to `Mypuzzle::size()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\untitled23.dir\build.make:85: untitled23.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/untitled23.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/untitled23.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: untitled23] Error 2
That's a linker error. It has nothing to do with the header file. It's telling you that the linker can't find the definition of Mypuzzle::size() anywhere in the compiled object code. This means that your project doesn't have any way of linking against the object code compiled from mypuzzle.cpp .
As salem c says, you can fix this by adding mypuzzle.cpp to your ptoject.
Also, note that your line 9 does nothing, because you're not actually doing anything with the value returned from Mypuzzle::size().