Reputation: 17253
I am following this example here. This is the output I get for make
admin@localhost qtest$ make
g++ -Wl,-O1 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64/lib -o qtest qtest.o -L/home/admin/Qt/5.3/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
make: *** [qtest] Error 1
admin@localhost qtest$
My cpp file is this
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
hello.show();
return a.exec();
}
Any suggestions on how I can fix this ?
Update
This is what I get after
sudo yum install mesa-libGL-devel -y
Trying again to build :
admin@localhost qtest$ make
g++ -Wl,-O1 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64/lib -o qtest qtest.o -L/home/admin/Qt/5.3/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
qtest.o: In function `main':
qtest.cpp:(.text.startup+0x22): undefined reference to `QApplication::QApplication(int&, char**, int)'
qtest.cpp:(.text.startup+0x4f): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
qtest.cpp:(.text.startup+0x74): undefined reference to `QWidget::resize(QSize const&)'
qtest.cpp:(.text.startup+0x7c): undefined reference to `QWidget::show()'
qtest.cpp:(.text.startup+0x81): undefined reference to `QApplication::exec()'
qtest.cpp:(.text.startup+0x8c): undefined reference to `QPushButton::~QPushButton()'
qtest.cpp:(.text.startup+0x94): undefined reference to `QApplication::~QApplication()'
qtest.cpp:(.text.startup+0xab): undefined reference to `QApplication::~QApplication()'
qtest.cpp:(.text.startup+0xbe): undefined reference to `QPushButton::~QPushButton()'
qtest.cpp:(.text.startup+0xce): undefined reference to `QPushButton::~QPushButton()'
collect2: error: ld returned 1 exit status
make: *** [qtest] Error 1
Upvotes: 2
Views: 1338
Reputation: 32675
To solve your error :
/usr/bin/ld: cannot find -lGL
you should install the missing mesa package by running the following install command as root or using sudo
:
sudo yum install mesa-libGL-devel -y
Upvotes: 4
Reputation: 3001
Open up your foo.pro file.
You probably have something like:
######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += foo.cpp
Add to the top, "QT += widgets", such that your file now reads:
######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################
QT += widgets
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += foo.cpp
then run qmake
and make
. This should allow it to find the relevant headers.
Your second error is not with libraries, but with finding the QtCore and QtWidgets modules of Qt.
Upvotes: 3