lemon_aiden
Posts: 4
Joined: Sat Feb 24, 2018 2:34 pm

wiringPi in C Language

Sat Feb 24, 2018 2:43 pm

Hi guys,

I recently bought a Raspberry Pi 3 Model B and I'm trying to figure out how to use the GPIO headers with C language. (Not C++!)
I successfully installed the wiringPi library but I very time a use the setup function, the complier says, 'undefined reference, 'wiringPiSetup'

Here's the code:

Code: Select all

#include <stdio.h>
#include <wiringPi.h>

int main()
{
	wiringPitSetup();
	pinMode(18, OUTPUT);
	
	for(;;)
	{
		digitalWrite(18, HIGH);
		delay(500);
		digitalWrite(18, LOW);
	}
	
	return 0;
}
Please help and thanks!

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4563
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: wiringPi in C Language

Sat Feb 24, 2018 2:57 pm

lemon_aiden wrote:
Sat Feb 24, 2018 2:43 pm
Hi guys,

I recently bought a Raspberry Pi 3 Model B and I'm trying to figure out how to use the GPIO headers with C language. (Not C++!)
I successfully installed the wiringPi library but I very time a use the setup function, the complier says, 'undefined reference, 'wiringPiSetup'

Here's the code:

Code: Select all

#include <stdio.h>
#include <wiringPi.h>

int main()
{
	wiringPitSetup();
	pinMode(18, OUTPUT);
	
	for(;;)
	{
		digitalWrite(18, HIGH);
		delay(500);
		digitalWrite(18, LOW);
	}
	
	return 0;
}
Please help and thanks!
In the code posted there's a typo: you have wiringPitSetup(); not wiringPiSetup ie. there's an extra 't' there (if the code posted was copy and pasted re-check the original).
Trev.
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

lemon_aiden
Posts: 4
Joined: Sat Feb 24, 2018 2:34 pm

Re: wiringPi in C Language

Sat Feb 24, 2018 11:31 pm

Yeah, thanks for reminding me the typo.
But still, after I fixed the typo, it keep says undefined reference to 'wiringPiSetup'

User avatar
joan
Posts: 13541
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: wiringPi in C Language

Sun Feb 25, 2018 3:23 am

Perhaps you are not linking in the wiringPi library? We can't tell, as you are not saying what you are doing.

User avatar
[email protected]
Posts: 1979
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: wiringPi in C Language

Wed Feb 28, 2018 12:17 pm

As well as the typo (compile with -Wall -Werror) you need to link in the library. Same way you'd link in the math library with -lm, link in wiringPi with -lwiringPi. wiringPi is not really intended for noobs to C programming though.

Also type: gpio readall to list the pin numbers - wiringPiSetup(); uses wiringPi pin numbers and pin 18 is almost certainly not what you want there. Also read this: https://projects.drogon.net/wiringpi-pin-numbering/

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 10 guests