Using WiringPi library with Raspberry PI cross-compiler

This tutorial shows how to develop a blinking LED project for Raspberry Pi in Visual Studio using the WiringPi library and our cross-toolchain.

Before we begin, ensure that VisualGDB is installed.

  1. If you do not have a LED prepared to connect to the expansion connector on the Raspberry Pi, please follow the steps 1-8 of our other blinking LED tutorial to prepare and connect a LED.
  2. Now create a basic Raspberry Pi cross-compilation project with VisualGDB by following this tutorial. Use the root account as the user account, as only root has direct access to hardware resources. If you don’t know the root password, login as the normal user, run ‘sudo su’ and then ‘passwd’ from the su shell to set it.01-project
  3. Next we install the wiringPi library on the Raspberry. In Visual Studio go to Tools->SSH Host Manager. Select the Raspberry Pi connection and click on ‘Open console’.02-sshhostmanager
  4. We follow the official installation steps.

    03-installwiringpiThis will build all the necessary files and install the libraries and include files into the corresponding directories on your Raspberry PI. The next step would be to import them to the cross-compiler.
  5. Go back to Visual Studio. Right-click on the project in Solution Explorer and choose VisualGDB Project Properties.04-projectproperties
  6. Go to the Makefile settings page. Click on ‘Synchronize sysroot’. This will download the include and library directories from your Raspberry PI to the corresponding directories in the cross-compiler toolchain so that the cross-compiler can use your newly installed wiringPI library.05-makefilesettings06-synchfolders07-syncprogress
  7. Once synchronization completes, we add ‘wiringPi’ and ‘pthread’ to the libraries list and add the ‘C:\SysGCC\raspberry\arm-linux-gnueabihf\sysroot\usr\local\include’ directory to the includes. Press ‘OK’ to exit the properties window. VisualGDB will quickly test whether the new settings are valid. If any errors are discovered, you will be able to fix them at this step.08-addlibraryname09-toolchaintest
  8. Next, let’s change the source code to actually blink a led. Replace the source with the following.
  9. Build the project.10-build
  10. Set a breakpoint as shown and start debugging. Step through the code and watch how the LED turns on and off.11-debugled_on