Solved Qt5 GUI and RF24 lib
-
Beginner with Linux and Qt (lest than 2 day expertise :)
Raspberry with NRF24l01 radio works fine using https://github.com/nRF24/RF24 with standard C++ and Python.
I would like to make a gui app with Qt and use this excellent lib with it.Now I stuck right in the beginning
#include <RF24/RF24.h> //lib found fine
RF24 *radio; //created radio
radio = new RF24(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //trying to int radio and not found reference to it.Error undefined reference to `RF24::RF24(unsigned short, unsigned short, unsigned int)' RF4 D:\PiProjects\RF4\RF4\RF4.cpp 23
Please advise how start with it.
TY -
@csaba911 it looks like you need to set the LIBS variable in your .pro file. See documentation
-
@pablo-j-rogina Being inexperienced as I’m need help with that too.
Tried to add Qt +=RF24 but that was a instant error. -
@csaba911 yeah, you probably will face several issues... It's like you're learning how to swim in a pond but you immediately want to cross the English Channel.
-
Hi and welcome to devnet,
Please re-read the documentation @Pablo-J-Rogina linked to. It's the exact part you need add to your pro file.
-
@pablo-j-rogina I can swim just fine (not in Qt water) this isn’t a rocket science I’m expecting it to be a short 100 line program so not the “English channel”
Can you just give me a example how do you reference a external lib like RF24.
Ty -
@csaba911 said in Qt5 GUI and RF24 lib:
I can swim just fine
I don't doubt that...
(not in Qt water)
That's exactly my point
Can you just give me a example how do you reference a external lib like RF24.
I've already pointed you to the proper documentation, and @SGaist suggested to re-read it, confirming it's a good lead. So I'm done here.
-
Added LIBS += -L/usr/local/lib -llibrf24 to debug.pro still getting the same error.
g++ -o Debug/RF5 Debug/RF5.o Debug/MainWindow.o Debug/moc_MainWindow.o -L/usr/local/lib -llibrf24 -lQt5Widgets -lQt5Gui -lQt5Core -lGLESv2 -lpthread -latomic
1> /usr/bin/ld: cannot find -llibrf24
1>collect2 : error : ld returned 1 exit status
1> make: *** [Makefile:165: Debug/RF5] Error 1 -
Confirmed that lib are installed
make: Nothing to be done for 'all'.
[Installing Libs to /usr/local/lib]
[Installing Headers to /usr/local/include/RF24]
make: Nothing to be done for 'all'.ldconfig -p | grep librf24
librf24.so.1 (libc6,hard-float) => /usr/local/lib/librf24.so.1
librf24.so (libc6,hard-float) => /usr/local/lib/librf24.soSo can you please help[ me to add whatever needed to be included ] !? or at least what file dir need for it ? Might not even work with Qt5 and we just wasting time.
-
It has nothing to do with Qt.
When linking to a library, remove the
lib
part of your library name. For example, when linking against zlib, the line is:LIBS += -lz
-
@sgaist Thanks its working now, at least compile without error.
-
-
@pablo-j-rogina you see after reading the lib section of the manual again I still don’t see any references that don’t add lib to librf24 ,that document assuming that I know that ?
“LIBS += -L/usr/local/lib -lmath” the library called libmath than it would be obvious to remove lib from it.
Thanks. -
@csaba911 said in Qt5 GUI and RF24 lib:
don’t add lib to librf24
Well, you said before you're good on other waters...
That feature is a common practice since a long ago, see GCC documentation for instance:
-llibrary
...
Some targets also support shared libraries, which typically have names like liblibrary.so.It's even used in the Makefiles of the RF24 project you use
LIBS+= -llittlewire-spi
Anyway, glad you have it working. And please don't forget to mark this post as solved, it might help other users. Thanks