jack01best
Posts: 17
Joined: Mon Apr 29, 2013 11:43 pm

How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 6:20 pm

Hi,

I want to compile c++ program which includes "wiringPi.h" header file on Raspberry Pi, but I do not how to compile it correctly.

Could you please tell me how to compile it correctly?

Thank you very much
Sincerely
Last edited by jack01best on Tue Nov 12, 2013 7:48 pm, edited 1 time in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20067
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 6:23 pm

You need to use the gcc compiler, which is installed as standard. Or, if you already have project, there is probably a make file you need to use

So (briefly)

gcc <name of c program>

or

make
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

User avatar
DougieLawson
Posts: 33398
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 6:45 pm

jamesh wrote:You need to use the gcc compiler, which is installed as standard. Or, if you already have project, there is probably a make file you need to use

So (briefly)

gcc <name of c program>

or

make
Re-read the question from the OP.

You can't compile a "wiringPi.h" file. You have to #include it into a xyzzy.c or foobar.cpp program.

So we need our OP to give a better description of what he's doing and what he's trying to achieve and why he's determined that "wiringPi.h" is the thing he needs to do it with.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

jack01best
Posts: 17
Joined: Mon Apr 29, 2013 11:43 pm

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 7:46 pm

DougieLawson wrote:
jamesh wrote:You need to use the gcc compiler, which is installed as standard. Or, if you already have project, there is probably a make file you need to use

So (briefly)

gcc <name of c program>

or

make
Re-read the question from the OP.

You can't compile a "wiringPi.h" file. You have to #include it into a xyzzy.c or foobar.cpp program.

So we need our OP to give a better description of what he's doing and what he's trying to achieve and why he's determined that "wiringPi.h" is the thing he needs to do it with.
Sorry, I means that I want to compile a c++ program which includes "wiringPi.h" header file, I don't know how to compile it.

aksommerville
Posts: 11
Joined: Sun Nov 10, 2013 1:13 pm

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 7:54 pm

What have you tried so far, and what happened?
Normally, it's just 'make' to compile C or C++ programs.

User avatar
AndyD
Posts: 2324
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 8:18 pm

I assume you have installed Wiring Pi using the instructions here.
The C++ compiler that most people use in Linux is g++.
You can follow Gordon's blink example here, just use g++ instead of gcc.
i.e.

Code: Select all

gcc -Wall -o blink blink.c -lwiringPi
sudo ./blink

jack01best
Posts: 17
Joined: Mon Apr 29, 2013 11:43 pm

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 8:55 pm

aksommerville wrote:What have you tried so far, and what happened?
Normally, it's just 'make' to compile C or C++ programs.
I want to compile C++ program but it is failure.

There are several errors as shown:
error: invalid suffix "HIGH" on floating constant
error: invalid suffix "LOW" on floating constant

I used the following command to compile:
g++ -std=c++0xBlink.cpp -oBlink -lwiringPi

jack01best
Posts: 17
Joined: Mon Apr 29, 2013 11:43 pm

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 8:57 pm

AndyD wrote:I assume you have installed Wiring Pi using the instructions here.
The C++ compiler that most people use in Linux is g++.
You can follow Gordon's blink example here, just use g++ instead of gcc.
i.e.

Code: Select all

gcc -Wall -o blink blink.c -lwiringPi
sudo ./blink
So you means that I can use the following command to compile C++ program?

Code: Select all

g++ -Wall -o blink blink.cpp -lwiringPi

User avatar
AndyD
Posts: 2324
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: How to compile C++ on Raspberry Pi

Tue Nov 12, 2013 9:40 pm

jack01best wrote: There are several errors as shown:
error: invalid suffix "HIGH" on floating constant
error: invalid suffix "LOW" on floating constant

I used the following command to compile:
g++ -std=c++0xBlink.cpp -oBlink -lwiringPi
That is odd. I get ...

Code: Select all

g++ -std=c++0x -Wall -o blink blink.cpp -lwiringPi
blink.cpp:2:7: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
Which is fair enough (main should be int main(void) in c++).

ganeshpadgalwar23
Posts: 1
Joined: Thu Jul 12, 2018 10:33 am

Re: How to compile C++ on Raspberry Pi

Thu Jul 12, 2018 10:48 am

I'm combinely using wiringPi Library and Rpi-rgb-led-matrix library in my .CC code

while doing this i'm getting below error ....if anyone know about this please reply...thank you ...in advance

example.cc -lwiringPi
/tmp/ccoNCX6j.o: In function `main':
text-example.cc:(.text+0x1fd0c): undefined reference to `rgb_matrix::GPIO::GPIO()'
text-example.cc:(.text+0x1fd1c): undefined reference to `rgb_matrix::GPIO::Init(int)'
text-example.cc:(.text+0x1fd7c): undefined reference to `rgb_matrix::RGBMatrix::RGBMatrix(rgb_matrix::GPIO*, int, int, int)'
collect2: error: ld returned 1 exit status

markkuk
Posts: 34
Joined: Thu Mar 22, 2018 1:02 pm

Re: How to compile C++ on Raspberry Pi

Thu Jul 12, 2018 12:03 pm

ganeshpadgalwar23 wrote:
Thu Jul 12, 2018 10:48 am
I'm combinely using wiringPi Library and Rpi-rgb-led-matrix library in my .CC code
If you are using multiple libraries then you must link your code with all of them.

Code: Select all

g++ example.cc -o example -lwiringPi -lrgbmatrix

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 7 guests