Page 1 of 1
wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:04 pm
by cdbean04
Hi,
I am trying to use wiringPi to get and LED to light (just to learn how to get everything talking) from an interface using Qt while using C++. I keep getting undefined reference to anything wiringPi i try to use. ex undefined reference to 'wiringPiSetup'
I have wiringPi.h in my include list and have wiringPi.h actually added to my project with my other .h files and nothing is working. Any help would be greatly apprecited.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:09 pm
by scotty101
Wow. This must be an urgent issue. You felt it necessary to create 4 topics.

For your information, it is considered bad practice to raise more than one topic on the same issue.

Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:17 pm
by MarkHaysHarris777
cdbean04 wrote:Hi,
I am trying to use wiringPi to get and LED to light (just to learn how to get everything talking) from an interface using Qt while using C++. I keep getting undefined reference to anything wiringPi i try to use. ex undefined reference to 'wiringPiSetup'
I have wiringPi.h in my include list and have wiringPi.h actually added to my project with my other .h files and nothing is working. Any help would be greatly apprecited.
An undefined reference is often a path problem. It cannot find a library, or the library is missing, or you spelled something wrong, or your path variable got clobbered, or some such.
Please minimize your code to just the wiringPI (get QT out of there) and then post your error messages... look over your source carefully for misspelled words, etc.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:19 pm
by rpdom
Have you included the WiringPi library files when building the project? On the compiler command line that would be a option like "-lwiringpi"
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:32 pm
by cdbean04
scotty101 wrote:Wow. This must be an urgent issue. You felt it necessary to create 4 topics.

For your information, it is considered bad practice to raise more than one topic on the same issue.

Sorry didn't know where to place it, will follow proper etiquette in the future.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:36 pm
by MarkHaysHarris777
cdbean04 wrote:
Sorry didn't know where to place it, will follow proper etiquette in the future.
No problem. Just so you know... many of use will logon from time to time and click "New Posts". We see whatever you post wherever you post it (from one list). So, if you post to four subforums the "New Posts" will show all of them in a row... looks a little goofy.
:-}
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 3:54 pm
by cdbean04
MarkHaysHarris777 wrote:cdbean04 wrote:Hi,
I am trying to use wiringPi to get and LED to light (just to learn how to get everything talking) from an interface using Qt while using C++. I keep getting undefined reference to anything wiringPi i try to use. ex undefined reference to 'wiringPiSetup'
I have wiringPi.h in my include list and have wiringPi.h actually added to my project with my other .h files and nothing is working. Any help would be greatly apprecited.
An undefined reference is often a path problem. It cannot find a library, or the library is missing, or you spelled something wrong, or your path variable got clobbered, or some such.
Please minimize your code to just the wiringPI (get QT out of there) and then post your error messages... look over your source carefully for misspelled words, etc.
Here is my code it is basically straight from the wiringPi site. Was just trying to get something going to test wiringPi out.
int pin;
int l;
if(wiringPiSetup() == -1)
exit(1);
for (pin = 0 ; pin < 8 ; ++ pin)
{
pinMode (pin, OUTPUT);
digitalWrite(pin,LOW);
}
pinMode (1, PWM_OUTPUT);
for(;;)
{
for (l = 0 ; l < 1024 ; ++l);
{
pwmWrite (1,1);
delay(1);
}
for (l = 1023 ; l >= 0; --l)
{
pwmWrite(1,1);
delay (1);
}
}
return ;
The error says
/home/pi/kClone/modeselect.cpp

error: undefined reference to `wiringPiSetup'
there are several other undefined reference errors, but they all look the same, just which reference is different.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 4:31 pm
by joan
As previously said you need to tell Qt to link against the wiringPi library. On the command line you'd add -lwiringpi to your build command.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 5:12 pm
by myoung008
If you are using qmake for your QT project, try adding the following to your project's .pro:
LIBS += -lwiringpi
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 5:39 pm
by cdbean04
Adding
LIBS += -lwiringpi
to my .pro file got rid of there errors I was having. Now I am getting an error that says
g++: error: -E or -x required when input is from standard input
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 6:12 pm
by myoung008
This one is a little more of a guess, but this line should probably be in .pro as well.
CONFIG += console
If that works it's the correct solution.
If it doesn't, I think you can pass non-libs flags over the LIBS line from my last answer. To be clear, this is a quick dirty hack and there will be a better answer.
What method / class are you using to access stdin? Qt4 or Qt5? Further compiling help will be easier if you post your .pro as well.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 6:35 pm
by cdbean04
myoung008 wrote:This one is a little more of a guess, but this line should probably be in .pro as well.
CONFIG += console
If that works it's the correct solution.
If it doesn't, I think you can pass non-libs flags over the LIBS line from my last answer. To be clear, this is a quick dirty hack and there will be a better answer.
What method / class are you using to access stdin? Qt4 or Qt5? Further compiling help will be easier if you post your .pro as well.
Here is my .pro I do not know what I need to add to it for it to access stdin. I know I am using Qt4, I am very knew to using Qt and Pi so please bare with my lack of knowledge.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = kClone
TEMPLATE = app
SOURCES += main.cpp\
modeselect.cpp \
heatmode.cpp \
noheatmode.cpp
HEADERS += modeselect.h \
heatmode.h \
noheatmode.h \
wiringPi.h
FORMS += modeselect.ui \
heatmode.ui \
noheatmode.ui
LIBS += -|wiringgpi
CONFIG += console
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 6:52 pm
by topguy
That looks like a "pipe" sign and not the "ell" 'l' I expect it to be.
Please learn to use the Code button in the forum editor for code.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 6:54 pm
by joan
topguy wrote:
That looks like a "pipe" sign and not the "ell" 'l' I expect it to be.
Please learn to use the Code button in the editor for code.
It is also spelt wrong.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 6:57 pm
by myoung008
The standard input error is probably due to a typo on the LIBS line you added.
Remove CONFIG += console. That wasn't the issue. You're writing a gui app anyway.
Thats a lowercase 'L' after the dash, not a vertical pipe. Also, there's two 'g's in wiringpi in your .pro.
Re: wiringPi undefined issues in Qt
Posted: Mon Jun 01, 2015 7:11 pm
by cdbean04
Figured out how to use the code button.
Code: Select all
TARGET = kClone
TEMPLATE = app
SOURCES += main.cpp\
modeselect.cpp \
heatmode.cpp \
noheatmode.cpp
HEADERS += modeselect.h \
heatmode.h \
noheatmode.h \
wiringPi.h
FORMS += modeselect.ui \
heatmode.ui \
noheatmode.ui
LIBS += -lwiringpi
CONFIG += console
I am getting another error, I know shocking.

error: cannot find -lwiringpi
Im assuming my path because it is still looking for the incorrectly typed library.
Re: wiringPi undefined issues in Qt
Posted: Wed Jun 03, 2015 7:03 am
by myoung008
So I took a little time and installed Raspbian and Wiring Pi on a spare Pi.
Try capital P.
The Wiring Pi build script also has a note about certain boards that may require wiringPiDev, so if you still have problems:
Re: wiringPi undefined issues in Qt
Posted: Wed Jun 03, 2015 6:10 pm
by cdbean04
The capital P corrected the error thank you very much.