Compiling custom applications in Linux with a Makefile and pkg-config
Note: See the preferred, simpler way of building in any platform using CMake above.
Apart of the CMake approach, MRPT also can be used from users programs built with GNU make by means of pkg-config.
Please, refer to the README and commented Makefile that can be found in MRPT/doc/mrpt_example1-with-Makefile/
.
For pkg-config to work you will have to either:
- Install MRPT in your system, from an Ubuntu repository (libmrpt-dev) or with a “sudo make install”.
- or, set the environment variable
PKG_CONFIG_PATH
to include the directorypkgconfig-no-install
, for example adding the following to your~/.basrc
file:
1export PKG_CONFIG_PATH=[YOUR_MRPT_BUILD_DIR]/pkgconfig-no-install:$PKG_CONFIG_PATH
Below follows an example Makefile which demonstrated the usage of pkg-config (or see it online):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# Example Makefile script # Purpose: Demonstrate usage of pkg-config with MRPT libraries # By: Jose Luis Blanco, 2010. # # ========================= *IMPORTANT* ================================ # For this method to work MRPT must be installed in your # system in a path accesible to pkg-config. To check if pkg-config # sees MRPT config files, execute: # pkg-config --list-all | grep mrpt # If no package appears, MRPT is not installed or something else is wrong. # ====================================================================== # # Set up basic variables: CC = g++ CFLAGS = -c -Wall LDFLAGS = # List of sources: SOURCES = test.cpp OBJECTS = $(SOURCES:.cpp=.o) # Name of executable target: EXECUTABLE = mrpt-example1 # MRPT specific flags: # Here we invoke "pkg-config" passing it as argument the list of the # MRPT libraries needed by our program (see available libs # with "pkg-config --list-all | grep mrpt"). # CFLAGS += `pkg-config --cflags mrpt-base` LDFLAGS += `pkg-config --libs mrpt-base` all: $(SOURCES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(OBJECTS) -o $@ $(LDFLAGS) .cpp.o: $(CC) $(CFLAGS) $< -o $@ clean: rm $(OBJECTS) $(EXECUTABLE) |