After I learned how to write makefile, I found that this was not enough to enable me to build all projects, such as KDE, OpenCV and so on. So I determined to learn CMake, an awesome building tool, which can be use on all platforms. You can download CMake by this page.
Create a file named
CMakeLists.txt and write as follows:
Maybe you should finish
hello.c with main function.
cmake . to generate
Makefile. After done, use
make to build all the project. Then you can use
./hello to run the program.
If you have two or more source files, you can use following:
But this is trouble when you build a big project, not elegant enough. So use follows instead:
aux_source_directory (<dir> <variable>) to add source files automatically.