fmas
Posts: 2
Joined: Tue Jun 19, 2018 11:42 pm

undefined reference to wiringpi

Tue Jun 19, 2018 11:54 pm

Hi team,

I know several posts have been made about this, but after looking through them I still cannot solve this issue. i am trying to control a stepper motor with wiringpi but when i try to compile i get the undefined reference to error for wiringpitsetupgpio, pinmode, digitalwrite and delay.

I compile in the terminal with this line:

Code: Select all

g++ -Wall -o stepper stepper.cpp -Iwiringpi
My code includes the wiringpi header and ive checked that the wiringpi folder is in the same directory as the text file. Ive also uninstalled and reinstalled wiringpi and upgraded and updated everything. I'm also a beginner to c++ and the rpi so any help would be greatly appreciated!

Thanks in advance.

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

Re: undefined reference to wiringpi

Wed Jun 20, 2018 11:42 am

Perhaps you meant

-lwiringpi

- lowercase L as it is a library.

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

Re: undefined reference to wiringpi

Wed Jun 20, 2018 1:58 pm

You might need any or all of:

-L some/library/directory -I some/include/directory -lsomeLinraryName

depending what you are up to.

That is uppercase L, upper case I, and lowercase l
(Why are browser fonts so awful?)

See "man g++" for details (it's only about 15000 lines of text!) or ask google.

fbe
Posts: 347
Joined: Thu Aug 17, 2017 9:08 pm

Re: undefined reference to wiringpi

Thu Jun 21, 2018 7:02 pm

If you use wiringpi functions you need to link to the wiringpi library. Add

Code: Select all

-lwiringPi
The first letter is a lowercase "L" here and the P must be uppercase ;).

Code: Select all

-Iwiringpi
(with leading uppercase I and lowercase P) doesn't hurt, but shouldn't be required, if you have the Raspbian wiringpi development package installed (Raspbian Stretch with desktop has it if you didn't remove it).

Return to “C/C++”