(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Mingw Build Environment

Description: A cross-compiling build environment for mingw programs.

Keywords: mingw

Tutorial Level: INTERMEDIATE

Next Tutorial: Mingw Packages Mingw Qt-Ros Packages

New in electric

  Show EOL distros: 

Not available

Not available.

Goal

This is for the control roboticists who love working in linux and get flustered when asked to build windows apps for the rest of the world (namely users/test engineers). It also allows a write once, compile in linux and windows approach to developing gui programs when used with qt.

Installation

Prep

If you haven't already, install the ros build environment python packages:

> sudo apt-get install python-pip
# If on lucid, get the latest pip
> sudo pip install --upgrade pip
> sudo pip install --upgrade rospkg rosdep vcstools rosinstall
# If you haven't initialised rosdep yet
> sudo rosdep init
# Finally cache it
> rosdep update

Sources

The following rosinstalls a known working set of sources for electric. Use it directly or as a reference:

> rosinstall ~/mingwros/src --nobuild https://raw.github.com/stonier/win_ros/electric/mingw_electric.rosinstall

Note that we're rosbuild2'ing now - which is essentially a purely cmake solution that will utilise a src and parallel build directory.

Also note that the above rosinstall will have done the defunctory native compile on your source directory. This is useful as it means you can utilise the existing setup.sh to help you traverse the source tree.

Final touches:

> cp ~/mingwros/src/cmake/CMakeLists.txt ~/mingwros/src
# We're using rosdep2 now (installed above), move rosdep1 so it doesn't collide
> mv ~/mingwros/src/ros/bin/rosdep ~/mingwros/src/ros/bin/rosdep_one

/!\ It will fail on rosdeps for ubuntu precise and later. Pass --nobuild if you want to avoid the error caused by changed rosdeps. If you manually install the appropriate rosdeps it should still work.

Toolchain

Installing the mingw_cross toolchain to ~/mingw (you can modify installation location by setting MINGW_INSTALL_PREFIX):

> . ~/mingwros/src/setup.bash
> rosdep install mingw_cross
> cd ~/mingwros/src/win_ros/mingw/mingw_cross
> make install

This will also add some MINGW_XXX variables to your .bashrc. If you have previous settings, make sure these are updated as required.

RosBuild2

Compilation

# In case you forgot to do earlier
> cp ~/mingwros/src/cmake/CMakeLists.txt ~/mingwros/src
# Proceed with the build
> . ~/mingwros/src/setup.bash
> mkdir ~/mingwros/build
> cd ~/mingwros/build
> cmake 
    -DCMAKE_TOOLCHAIN_FILE=${MINGW_CMAKE_TOOLCHAIN_FILE}
    -C ${MINGW_CMAKE_ROS_CONFIG_FILE}
    ../src
> cd roscpp_tutorials; make -j5; cd ..
> cd qt_tutorials; make -j5; cd ..

The MINGW_CMAKE_XXX variables correspond to those configured in your .bashrc as described above.

Modifying the Build

> . ~/mingwros/src/setup.bash
> cd ~/mingwros/build
> ccmake .

You can then change variables such as the build type (actually, that's probably the only one you really want to modify.

Running

All the binaries are built statically. That means they are entirely self-sufficient and standalone. It also means they're big, but as we're primarily using these just for monitoring and debugging purposes, optimisation isn't a big deal.

Simply copy the binaries in ~/mingw/build/bin to your windows machine. Fire up a roscore on a linux machine and then run the qt tutorials - make sure you enter the correct variables for the ROS_MASTER_URI and ROS_IP. Alternatively you can just start a windows shell and set the environment variables before running any of the roscpp/qt tutorials.

Goal

This is for the control roboticists who love working in linux and get flustered when asked to build windows apps for the rest of the world (namely users/test engineers). It also allows a write once, compile in linux and windows approach to developing gui programs when used with qt.

Installation

Prep

If you haven't already, install the ros build environment python packages:

# Install from apt-get
> sudo apt-get install python-rosdep python-rosinstall python-rospkg python-empy python-nose
# If you haven't initialised rosdep yet
> sudo rosdep init
> rosdep update

Sources

For now, cross-compiling with mingw is done completely from source with rosinstall. It does not use a binary (e.g. deb) based repository.

> rosinstall --catkin ~/win/src https://raw.github.com/stonier/win_ros/master/mingw_fuerte.rosinstall

This .rosinstall file is useful as a reference to start adding your own stacks to the rosinstall. The typical use case for mingw programs is just to communicate to the linux ros control platform, so ordinarily you'll only need to add msg/srv stacks to the above rosinstaller.

Note that we're using catkin now - which is essentially a purely cmake solution that will utilise a src and parallel build directory. It will also mean that your packages must be upgraded for catkin compiles. While transitioning from rosbuild to catkin this may be an issue, if so - you may wish to use electric until more stacks are converted to catkin.

Finally, apply the currently held patches (most of these are in the middle of getting merged upstream):

> cd ~/win/src
> ./win_ros/win_patches/apply_mingw_patches

Toolchain

Installing the mingw_cross toolchain to ~/mingw (you can modify installation location by setting MINGW_INSTALL_PREFIX):

> cd ~/win/src/win_ros/mingw/mingw_cross
> # Not working with catkin and rosdep2 yet, but should later
> # rosdep install mingw_cross
> # Instead, make sure you have the dependencies installed, e.g. ubuntu:
> sudo apt-get install mercurial xz-utils flex bison yasm autoconf libtool intltool scons
> make install

This takes quite some time. To speed things up with parallel jobs, edit the Makefile and set the JOBS variable.

In addition, it will add the variables MINGW_ROOT, MINGW_CMAKE_TOOLCHAIN_FILE and MINGW_CMAKE_ROS_CONFIG_FILE and update your PATH in ~/.bashrc.

Catkin

Compilation

# In case you forgot to do earlier
> cd ~/win
> mkdir build
> cd build
> cmake 
    -DCMAKE_TOOLCHAIN_FILE=${MINGW_CMAKE_TOOLCHAIN_FILE} 
    -C ${MINGW_CMAKE_ROS_CONFIG_FILE} 
    ../src
> cd ros_tutorials/roscpp_tutorials; make -j5; cd ..
> cd qt_ros/qt_tutorials; make -j5; cd ..

Note that the bash variables are defined in ~/.bashrc for convenience (see above). The -j# option sets up parallel builds which is useful for speeding things up on a multi-core system.

Modifying the Build

> cd ~/win/build
> ccmake .

You can then change variables such as the build type (actually, that's probably the only one you really want to modify.

Running

All the binaries are built statically. That means they are entirely self-sufficient and standalone. It also means they're big, but as we're primarily using these just for monitoring and debugging purposes, optimisation isn't a big deal.

Simply copy the binaries in ~/win/build/bin or ~/win/build/_stack_/_package_/bin to your windows machine. Fire up a roscore on a linux machine and then run the qt tutorials - make sure you enter the correct variables for the ROS_MASTER_URI and ROS_IP. Alternatively you can just start a windows shell and set the environment variables before running any of the roscpp/qt tutorials.

Wiki: mingw_cross/Tutorials/Mingw Build Environment (last edited 2012-05-03 01:46:27 by DanielStonier)