5.4 Using Webots Makefiles5.4.1 What are MakefilesThe compilation of Webots C/C++ and Java controllers can be configured in the provided Makefiles. A controller's Makefile is a configuration file used by the make utility and that optionally specifies a list of source files, how they will be compiled and linked to create the executable program. Note that Python, URBI and MATLABTM are interpreted languages and therefore they don't need Makefiles. So if your using any of these programming languages or Visual C++ then you can ignore this section. When using C/C++ or Java, the presence of a Makefile in the controller directory is necessary. If the Makefile is missing Webots will automatically propose to create one. This Makefile can be modified with a text editor; its purpose is to define project specific variables and to include the global Makefile.include file. The global Makefile.include file is stored in WEBOTS_HOME/resources/controllers directory; it contains the effective build rules and may vary with the Webots version. Note that Webots Makefiles are platform and language independent. 5.4.2 Controller with Several Source Files (C/C++)If a controller requires several C/C++ source files they need to be specified in the Makefile. The name of each source file must be listed, using one of these variables:
Every source file specified using these variables, will be added to the controller build. In addition dependency files will be automatically generated by the make command in order to minimize the build. Note that these variables should not be used in any language other than C or C++. For example if a controller has several .c source files, then this can be specified like this in the controller's Makefile:
5.4.3 Using the Compiler and Linker Flags (C/C++)These two variables can be used to pass flags to the gcc compiler or linker.
Adding an External Library (C/C++)Webots C/C++ controllers are regular binary executable files that can easily be compiled and linked with external libraries. To add an external library it is only necessary to specify the path to the header files, and the path and name of the library in the controller's Makefile. For example the -Idir flag can be used to add a directory to search for include files. The LIBRARIES variable can be used to pass flags to the linker. For example the -Ldir flag can be used to add a directory to search for static or dynamic libraries, and the -l flag can be used to specify the name of a library that needs to be linked with the controller. For example, let's assume that you would like to add an external library called XYZLib. And let's assume that the library's header files and .dll file are located like this (Windows):
Adding Debug InformationIf you need to debug your controller, you need to recompile it with the -g flag, like this:
C/C++ Code OptimizationIf you need to optimizes your controller code, you can use the -O1, -O2 or -O3 flags. For example:
![]() ^ page top ^ |
| E-mail to webmaster | Last updated: | Copyright © 2010 Cyberbotics Ltd. |