在Fedora 20上使Qt应用程序失败:/ usr / bin / ld:找不到-lGL

时间:2014-11-17 04:38:36

标签: c++ linux qt makefile

我在这里关注example。 这是我得到的输出

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$ 

我的cpp文件是这个

#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();
}

有关如何解决此问题的任何建议?

更新

这是我得到的

 sudo yum install mesa-libGL-devel -y

再次尝试构建:

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

2 个答案:

答案 0 :(得分:4)

解决您的错误:

  

/ usr / bin / ld:找不到-lGL

您应该以root用户身份或使用sudo运行以下安装命令来安装缺少的mesa软件包:

sudo yum install mesa-libGL-devel -y

答案 1 :(得分:3)

打开你的foo.pro文件。

你可能有类似的东西:

######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################

TEMPLATE = app
TARGET = test
INCLUDEPATH += .

# Input
SOURCES += foo.cpp

添加到顶部&#34; QT + =小部件&#34;,以便您的文件现在显示为:

######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################

QT += widgets

TEMPLATE = app
TARGET = test
INCLUDEPATH += .

# Input
SOURCES += foo.cpp

然后运行qmakemake。这应该允许它找到相关的标题。

您的第二个错误不是库,而是查找Qt的QtCore和QtWidgets模块。