cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:04 pm

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.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:09 pm

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. :!:
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:17 pm

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.
marcus
:ugeek:

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:19 pm

Have you included the WiringPi library files when building the project? On the compiler command line that would be a option like "-lwiringpi"

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:32 pm

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.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:36 pm

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.
:-}
marcus
:ugeek:

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 3:54 pm

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:-1: error: undefined reference to `wiringPiSetup'
there are several other undefined reference errors, but they all look the same, just which reference is different.

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

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 4:31 pm

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.

myoung008
Posts: 55
Joined: Mon Mar 18, 2013 9:56 pm

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 5:12 pm

If you are using qmake for your QT project, try adding the following to your project's .pro:

LIBS += -lwiringpi

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 5:39 pm

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

myoung008
Posts: 55
Joined: Mon Mar 18, 2013 9:56 pm

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 6:12 pm

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.

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 6:35 pm

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

User avatar
topguy
Posts: 6491
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 6:52 pm

Code: Select all

LIBS += -|wiringgpi
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.

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

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 6:54 pm

topguy wrote:

Code: Select all

LIBS += -|wiringgpi
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.

myoung008
Posts: 55
Joined: Mon Mar 18, 2013 9:56 pm

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 6:57 pm

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.

Code: Select all

LIBS += -lwiringpi
Thats a lowercase 'L' after the dash, not a vertical pipe. Also, there's two 'g's in wiringpi in your .pro.

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Mon Jun 01, 2015 7:11 pm

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.

:-1: error: cannot find -lwiringpi
Im assuming my path because it is still looking for the incorrectly typed library.

myoung008
Posts: 55
Joined: Mon Mar 18, 2013 9:56 pm

Re: wiringPi undefined issues in Qt

Wed Jun 03, 2015 7:03 am

So I took a little time and installed Raspbian and Wiring Pi on a spare Pi.

Try capital P.

Code: Select all

LIBS += -lwiringPi
The Wiring Pi build script also has a note about certain boards that may require wiringPiDev, so if you still have problems:

Code: Select all

LIBS += -lwiringPi -lwiringPiDev

cdbean04
Posts: 31
Joined: Thu May 28, 2015 3:28 pm
Location: Evansville Indiana

Re: wiringPi undefined issues in Qt

Wed Jun 03, 2015 6:10 pm

The capital P corrected the error thank you very much.

Return to “C/C++”