Tutorial: Cross-compiling C++ projects for Beaglebone
In this tutorial we will show how to use a cross-toolchain to quickly build and debug Beaglebone projects from Visual Studio using VisualGDB 4.1 or later. Before you begin with the cross-compiler it is recommended to follow this tutorial to create a basic project using direct compilation on Beaglebone.
- Start Visual Studio. Go to File->New->Project and select VisualGDB->Linux Project Wizard. Specify the name and directory for your project:
- On the first wizard page select “Application” and click “Next”:
- The second wizard page allows switching between compiling your source code on the Beaglebone board and using a cross-compiler hosted on Windows. Select “Build the project locally” and then pick “Beaglebone” from the cross-toolchain list:Ensure that the toolchain you download matches the Beaglebone image you are using. You can find out the compatible images on the Beaglebone toolchain page.
- If you don’t have the toolchain installed yet, VisualGDB will automatically download and install it for you:
- Select your Beaglebone board in the “Deployment computer” field:
- If you have just downloaded the toolchain it is recommended to synchronize the sysroot. This will take a few minutes, but will ensure that both the toolchain and your device are using the same headers and libraries and that the binaries produced by the toolchain will be 100% compatible with your device. Click “Synchronize headers and libraries” and synchronize with default settings:
- Once the synchronization is done, click “Finish” to have your project created. Build it with Ctrl-Shift-B. Note that the building with a cross-toolchain is much faster then building it on Beaglebone:
- Put a breakpoint in main() and start debugging by pressing F5. Once the breakpoint is hit you can use the common debugging techniques (e.g. stepping or viewing memory) to debug your program:
- When done debugging, right-click on the project in Solution Explorer and select “VisualGDB Project Properties”. The VisualGDB Project Properties window allows changing various settings related to building and debugging (e.g. specifying additional libraries or resynchronizing the sysroot):