Just for interest, why do you need C++ for that instead of C?
I think there is big difference in C and C++ language. C is structural language where as C++ is object oriented language. I have read the forum post. Most of people suggest to learn c++ for Raspberry Pi. Just for my interest I want to write c++ program for LED, switch and servo motor. I searched on google but I didn't find example program so I thought I should asked here.
Well if you are certain you need the power of C++ (and can cope with its hideous complexity), then its easy as there is a C++ compiler included in Raspbian.
Yes indeed there is. C++ is vastly more powerful and complex than C. But as has been pointed out above, C++ includes C as a subset.
What is a structural language?C is structural language where as C++ is object oriented language.
They do not. Mostly Python is recommended because it is great for beginners.Most of people suggest to learn c++ for Raspberry Pi.
That's all I have already explain in my first post. I think I couldn't explain my question very well..jahboater wrote: ↑Thu Jun 07, 2018 4:30 pmWell if you are certain you need the power of C++ (and can cope with its hideous complexity), then its easy as there is a C++ compiler included in Raspbian.
Raspbian is the official OS for the Pi. The most commonly used languages are Python or C/C++. You do not need to install anything.
Use any editor you like (nano or vim are commonly used), and write your program - say "led.cpp" to start with.
Compile it with:
g++ led.cpp -o led
You will likely need to add the pigpio or WiringPi libraries which are also included in Raspbian.
Then run your program with
and hopefully your led will flash on or off.
Code: Select all
g++ -lwiringPi led.cpp -o led
I am not too good but I am not too bad in c++ programming. I did practice on GCC compiler for basic learning . I have programmed node mcu esp8266 using arduino ide in c++ language.julyjim wrote: ↑Sun Jun 10, 2018 12:16 am
However, if you are serious about learning programming in C++ do not start with I/O hardware interfacing.
Also using "commands" is not C++ programming.
Find IDE of some substance and "write " simple "hello word" in C++.
If your really want to "blink LED" - there are many copies of "GPIO" "library" to do that - but in C.
I have spent few months "porting" it to C++, and learn a lot about BCM2835 processor hardware in the process.
At present the code is still "under construction " and not open to public scrutiny.
Best of luck to you.
As a user of Arduino (Mega, Due, esp8266) and the Raspi I daresay that there are worlds in between the simplified Arduino Sketch C++ and "real" C++ for Linux. As already stated, there is no all-in-one IDE and API to Pi like Arduino for microprocessors.