I apologize if this has been answered, I’ve searched for some time and could not find a straight answer.
I’m used to windows visual c++ where I use a header file (*.h) for declaring classes and it’s functions and a source file (*.cpp) where the actual class’s functions are coded in detail. I am now working under Linux using Kdevelop which uses cmake. I’ve created some header files with classes in them and declared their functions and then coded the functions in their respective source files. Every time I try to build, I get errors that tells that Class::function() is an undefined reference. If I add the actual function in the header file, building works fine. So I am assuming that cmake is not linking correctly the respective source file for the header file. I was assuming that this would happen automatically, but I’m now guessing that this is not the case. How can I do that? For every header file I create, using the exact same name for the source file, have it all linked and build?
If this has been answered already, please post a link, if not, I would love a simple explanation. I understand there are many ways of doing this (autoconf, make dep, etc?) but for now I’m stuck with cmake.
Here is a example CMakeLists.txt for a project named Test that links two source files into an executable named test.
if you want to add more source files just add them to the list.