chadouv
Posts: 1
Joined: Fri Sep 20, 2019 6:23 pm

Raspberry Pi project in c++ build on Windows

Fri Sep 20, 2019 6:28 pm

Hello,

I am building an C++ application for RPi but the problem is tha compiling takes too long and it is slowing me down. I am using a RPi 1. My RPi 2 is reserved for another project.

I there a way to build my project on Windows using VS Code or VS Studio and run on RPi? I am looking for an online tutorial to setup my developement environment.

Thanks
C.D.

bdrmachine
Posts: 35
Joined: Fri Sep 20, 2013 8:52 pm

Re: Raspberry Pi project in c++ build on Windows

Sat Sep 21, 2019 2:49 am

Use Netbeans 11 with the c/c++ plugin. on your PC and SSH to connect to your Pi.

Heater
Posts: 13878
Joined: Tue Jul 17, 2012 3:02 pm

Re: Raspberry Pi project in c++ build on Windows

Sat Sep 21, 2019 2:58 am

Typically when I'm developing code for the Pi in C, C++ or Rust I do most of the development on a PC/Laptop. It's a lot faster and affords the luxury of whatever IDE and other tools one may need.

However I do not cross compile for the Pi, I build it as a program for Linux or Windows. I can run and test the project on the PC as a Linux/Windows application. Then, when significant chucks of code have been created I move the sources to a Pi and build it there for testing in it's target environment. I might make some fixes on the Pi and then move back to the PC for the next phase.

A few things make this work flow very nice: Keep the source in a git repository on github or bitbucket etc. That makes it easy to clone and pull to different places quickly and make changes anywhere. The Linux Subsystem for Windows provides a very nice Linux environment. For GUI applications there is QtCreator for GUI applications, with Qt one can develop on Windows or Mac and the code will run fine on the Pi when moved there.

Of course there are Pi specific parts of such projects that cannot be run on the PC. Those that use the GPIO and so on. For those parts I create "mocks" or "stubs" that stand in for the actual hardware when running on the PC. This is a good thing because it means one can use such mocks and stubs to do unit testing of code on the PC.

I try to stay away from cross-compiling as much as possible. It's a pain to set up and work with. Also building code to run on different platforms tends to show up bugs one might not other wise find.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 4832
Joined: Wed Feb 04, 2015 6:38 pm

Re: Raspberry Pi project in c++ build on Windows

Sat Sep 21, 2019 6:00 pm

chadouv wrote:
Fri Sep 20, 2019 6:28 pm
I am building an C++ application for RPi but the problem is tha compiling takes too long and it is slowing me down. I am using a RPi 1. My RPi 2 is reserved for another project.
The simplest answer perhaps is just to look at getting the new Pi4 model.
Compiling is fast on the Pi4 for any sized program (with optimization, around 2000 source lines per sec).
Up to 4GB of memory and quad Cortex-A72 CPU cores running at 1.5GHz by default.

Compiling native is always easier than cross compiling.


Return to “C/C++”