iCub-main
|
In this short tutorial we learn how to use CMake. We compile a simple test program that links all YARP libraries. This program is trivial and does not use the robot yet.
We assume you have:
First we need to prepare the main.cpp.
Open a text editor and type the following:
Save it to main.cpp.
This program will print the "Hello iCub" message for some times, waiting 0.5 seconds at every iteration of the while loop.
Let's see now how to compile this program.
Go back to your text editor and write the following file:
Now save this file as CMakeLists.txt, in the same directory as your main.cpp file.
This code tells cmake to produce appropriate project files to compile an executable named hello, using the file main.cpp. It also links in yarp libraries.
Now run cmake:
cmake ./
If cmake complains about not being able to localize YARP, it means that you have not followed correctly the procedure in the manual about the compilation of YARP. In particular, check that you have correctly set the environment veriables YARP_DIR. It is also possible to manually set these values, but we do not recommend it.
Now you are ready to compile this example using your favorite compiler, and execute it.
In linux: