Jump to content

C++ wiringPi undefined reference to error

this is the error

inputgpio.o: In function `main':inputgpio.cpp:(.text.startup+0x4): undefined reference to `wiringPiSetup'inputgpio.cpp:(.text.startup+0x18): undefined reference to `pinMode'inputgpio.cpp:(.text.startup+0x20): undefined reference to `digitalRead'collect2: ld returned 1 exit statusmake: *** [input] Error 1

this is my code

#include <iostream>#include <wiringPi.h>using namespace std;int main(){if(wiringPiSetup() == -1){        cout << "gpio not functioning " << endl;}int input;pinMode (1, INPUT);input = digitalRead(1);if((input == 1)){        cout << "input = true" << endl;}}

Background info,
i wrote this using vim, compiled using qmake, and i did add wiringPi.h to the sources.

CPU: i7 4770k@4.3Ghz GPU: GTX 780ti Motherboard: ROG maximus vi formula PSU: Evga supernova 1000w Platinum

Case: NZXT Switch 810 Memory: g.skill ripjaws X Cooler: Corsair h100i(getting custom loop when i get money next) Storage: Samsung 840 evo 250gb Keyboard: Corsair K95 Mouse: SteelSeries Rival

Link to comment
https://linustechtips.com/topic/198363-c-wiringpi-undefined-reference-to-error/
Share on other sites

Link to post
Share on other sites

thanks, but i figured it out. when i compiled it didn't include wiringPi.h well at least the compiler i was using anyway. i changed and it worked great

CPU: i7 4770k@4.3Ghz GPU: GTX 780ti Motherboard: ROG maximus vi formula PSU: Evga supernova 1000w Platinum

Case: NZXT Switch 810 Memory: g.skill ripjaws X Cooler: Corsair h100i(getting custom loop when i get money next) Storage: Samsung 840 evo 250gb Keyboard: Corsair K95 Mouse: SteelSeries Rival

Link to post
Share on other sites

thanks, but i figured it out. when i compiled it didn't include wiringPi.h well at least the compiler i was using anyway. i changed and it worked great

 

I usually just compile in the terminal. I have use two tabs, one for editing and the other for running programs :)

 

g++ file.cpp -o file -lwiringpi

 

btw are you just getting into using wiringPi? :D

ZerueLX11

Check me out! LTT Forum Profile!

Link to post
Share on other sites

I usually just compile in the terminal. I have use two tabs, one for editing and the other for running programs :)

 

g++ file.cpp -o file -lwiringpi

yea i usually just run it through ssh, but what worked for me was g++ -Wall -o -outputfile inputfile -lwiringPi

CPU: i7 4770k@4.3Ghz GPU: GTX 780ti Motherboard: ROG maximus vi formula PSU: Evga supernova 1000w Platinum

Case: NZXT Switch 810 Memory: g.skill ripjaws X Cooler: Corsair h100i(getting custom loop when i get money next) Storage: Samsung 840 evo 250gb Keyboard: Corsair K95 Mouse: SteelSeries Rival

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×