Since Arduino uses C++ for its programming with libraries that are specific to Arduino, is it possible to compile your sketch and have it run as a C++ program on a Raspberry Pi? I saw there was RasPiArduino for the Raspberry Pi 1/2 but it doesn;t seem to support 3. I am looking to run a program I made on my Arduino boards on my Raspberry Pi with a few modifications.(Note: I posted a similar question before but all anyone focused on was the specific example and not the question as a whole.) What would I need to change for it to run, and what would I need to carry over to run my Arduino programs on the Raspberry Pi?
You are absolutely correct that Arduino sketches are C(++) with a set of custom libraries
In principle if one replaces or provides a wrapper for each imported/used library with an API compatible raspberry pi port of that library , then the code will compile as is. There is an additional complication that Arduino provides
void main() entry point for you as part of the core library application bootstrap, this function does much platform specific initialization and must also be ported.
However this is only half the picture. An arduino sketch is a baremetal application: the entire CPU , every peripheral, and all of physical memory is freely available to you. Many libraries provide functionality that is impossible to directly port in a user space application running on Linux, although equivalent functionality may be found, certain design patterns common in Arduino sketches and baremetal plat forms- things like busy waits, while loop on a status bit, random delays etc. Will not be directly portable or will behave unpredictably . Your application may break and require architectural redesign to function on Linux.
There something called cross-compilation toolchain. You might want to look into that. One example Link: https://crosstool-ng.github.io/
Cross-compilation toolchain helps in creating binaries that run for different platform than the platform where toolchain runs.