Solution Qt5.7.0 cannot FIND-LGL

Source: Internet
Author: User
Tags probook

Long time no QT, this time to do a protocol editor, on Ubuntu 14.04 installed the latest version of Qt 5.7.0. The interface switch to Flat style, the first feeling is good. According to the default steps to create a GUI program, compiled run, reported a mistake: cannot find-lgl.

As a accustomed makefile programmer, know that the library file is missing, and the name should be LIBGL.A or libgl.so. Search the web and find that GL is the abbreviation for OpenGL, which is obviously a lack of OpenGL's development library. The installation commands are:sudo apt-get install libgl1-mesa-dev。在网上搜索关键字"cannot find -lGL",得到的答案就是安装开发库。

OpenGL is a huge library, and I just do an editor, and not what 2D, 3D program, obviously not use OpenGL. So I went to StackOverflow to search for a bit, found the answer: Http://stackoverflow.com/questions/18406369/qt-cant-find-lgl-error

You don't need to install anything. LIBGL are already installed with Ubuntu, you just need to soft link it. (works for Ubuntu 14.x and 15.x)1. FirstLocateThe GL library2. Then link it under/usr/Lib3. If The library is missing, it can installed via libgl1-mesa-Dev Packagehere is what you could Dothis:$LocateLibgl/usr/lib/i386-linux-gnu/mesa/libgl.so.1/usr/lib/i386-linux-gnu/mesa/libgl.so.1.2.0/usr/lib/x86_64-linux-gnu/libglew.so.1.10/usr/lib/x86_64-linux-gnu/libglew.so.1.10.0/usr/lib/x86_64-linux-gnu/libglewmx.so.1.10/usr/lib/x86_64-linux-gnu/libglewmx.so.1.10.0/usr/lib/x86_64-linux-gnu/libglu.so.1/usr/lib/x86_64-linux-gnu/libglu.so.1.3.1/usr/lib/x86_64-linux-gnu/mesa/libgl.so.1/usr/lib/x86_64-linux-gnu/mesa/libgl.so.1.2.0/usr/lib/x86_64-linux-gnu/mesa-egl/libglesv2.so.2/usr/lib/x86_64-linux-gnu/mesa-egl/libglesv2.so.2.0.0$ sudo LN-s/usr/lib/x86_64-linux-gnu/mesa/libgl.so.1/usr/lib/libgl.so

My system does exist libgl.so.1.2.0 this file. He solved the problem according to his method. If your system does not have this file, it's really going to be installed.

The program can run, but it doesn't solve my question: Does the QT GUI really need to rely on OpenGL? Search the official documents and find the answer: http://doc.qt.io/qt-5/linux-requirements.html

In the list of QT for X11 requirements, there is no OpenGL. In OpenGL dependencies, it is also indicated that using OpenGL in QT requires # include <QtOpenGL> and requires QT + + OpenGL in the. Pro project configuration file. This means that my program does not rely on OpenGL at all, and decides to test it manually.

Clean up the project, recompile it once, and switch to the compiled output:

Can see the parameters of the compilation, I manually go to the corresponding directory, and then change the compilation parameters:

RM speditor [email protected]-HP-PROBOOK-4446S:~/DOCUMENTS/CODE/BUILD-SPEDITOR-DESKTOP_QT_5_7_0_GCC_ 64bit-debug$ g++-wl,-rpath,/opt/qt5.7.0/5.7/gcc_64/lib-o speditor main.o mainwindow.o moc_ MAINWINDOW.O   -l/opt/qt5.7.0/5.7/gcc_64/lib-lqt5widgets-l/usr/lib64-lqt5gui-lqt5core-  Lpthread[email protected]-hp-probook-4446s:~/documents/code/build-speditor-desktop_qt_5_7_0_gcc_ 64bit-debug$./Speditor [email protected]

Do not use the-LGL parameter to compile the linked program, also can run normally, verify my idea.

Since you don't rely on OpenGL, why link OpenGL? First add extra-LGL in the link parameter to the generated program has no effect, your program does not call OpenGL method, there will be no additional code link in. QT is a cross-platform library that contains some 3D libraries. Qt Creator is very intelligent to generate dependencies based on the program, which is a bit difficult and unnecessary. So I think the author simply adds these common libraries to the link parameters, solve everything.

These pre-determined parameters, placed on the platform in the installation directory of the Mkspecs directory, such as mine is in the opt/qt5.7.0/5.7/gcc_64/mkspecs. By keeping a closer look at the link parameters, you will find

-i/opt/qt5.7.0/5.7/gcc_64/mkspecs/linux-g++ this to the path, which is the cross-platform configuration of QT. On my machine, in

/opt/qt5.7.0/5.7/gcc_64/mkspecs/common/linux.conf can find such a configuration

# # Qmake Configuration forCommon Linux#qmake_platform+=linuxinclude (unix.conf) Qmake_cflags_thread+= -D_reentrantqmake_cxxflags_thread+=$ $QMAKE _cflags_threadqmake_lflags_gcsections=-wl,--gc-Sectionsqmake_lflags_rel_rpath=-wl,-Z,originqmake_rel_rpath_base=$ORIGINQMAKE _incdir=Qmake_libdir=qmake_incdir_x11=qmake_libdir_x11=Qmake_incdir_opengl=Qmake_libdir_opengl=Qmake_incdir_opengl_es2=$ $QMAKE _incdir_openglqmake_libdir_opengl_es2=$ $QMAKE _libdir_openglqmake_incdir_egl=Qmake_libdir_egl=QMAKE_INCDIR_OPENVG=QMAKE_LIBDIR_OPENVG=Qmake_libs=Qmake_libs_dynload= -ldlqmake_libs_x11=-lxext-lx11-Lmqmake_libs_nis= -Lnslqmake_libs_egl= -Leglqmake_libs_opengl= -Lglqmake_libs_opengl_es2= -LGLESV2QMAKE_LIBS_OPENVG= -Lopenvgqmake_libs_thread= -Lpthreadqmake_libs_libudev= -Ludevqmake_cflags_wayland=Qmake_incdir_wayland=qmake_libs_wayland_client=-lwayland-Clientqmake_libs_wayland_server=-lwayland-Serverqmake_libdir_wayland=Qmake_defines_wayland=Qmake_wayland_scanner= wayland-SCANNERQMAKE_CFLAGS_XCB=QMAKE_LIBS_XCB=QMAKE_DEFINES_XCB=Qmake_ar=arcqsqmake_objcopy=objcopyqmake_nm= NM-Pqmake_ranlib=Qmake_strip=Stripqmake_stripflags_lib+ =--strip-unneeded

If your program does not need OPENGL, and later do not intend to write such a program, the QMAKE_LIBS_OPENGL =-lgl this to remove it.

Solution Qt5.7.0 cannot FIND-LGL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.