GLEW(OpenGL Extension Wrangler Library)是一个开源的C/C++库,它用于管理OpenGL的扩展功能。GLEW能够查询OpenGL的扩展,确定它们是否可用,并在你的应用程序中动态地使用它们。
在Ubuntu上安装GLEW(OpenGL Extension Wrangler)可以通过以下步骤进行:
apt安装
打开终端(Terminal)。
更新软件包列表:
sudo apt update
安装GLEW库:
sudo apt install libglew-dev
这将安装GLEW的开发库,它包含了必要的头文件和链接库,以便你在Ubuntu上进行OpenGL开发时使用GLEW。
请注意,通过apt安装的GLEW版本可能与最新发布的版本不同步。
CMake安装
如果你需要特定版本或最新版本的GLEW,你可能需要从GLEW的官方网站下载源码并按照其提供的安装说明进行编译和安装。
完成安装后,你可以通过编写一个简单的OpenGL程序来测试GLEW库是否正常工作。
GLEW(OpenGL Extension Wrangler)的官方网站是 http://glew.sourceforge.net/,你可以在这个网站上下载GLEW的源代码并进行安装。
以下是基于源代码安装GLEW的一般步骤:
1:下载压缩包
访问GLEW的官方网站,找到并下载最新版本的GLEW源代码压缩包,通常是一个.zip或.tgz文件。
解压下载的压缩包。这可以通过在终端使用unzip命令(对于.zip文件)或tar -xzf命令(对于.tgz文件)来完成。
wcx@wcx-Ubuntu:~/Downloads$ ls
glew-2.1.0.zip NVIDIA-Linux-x86_64-550.54.14.run
wcx@wcx-Ubuntu:~/Downloads$ unzip glew-2.1.0.zip
Archive: glew-2.1.0.zip
creating: glew-2.1.0/
creating: glew-2.1.0/auto/
creating: glew-2.1.0/auto/core/
creating: glew-2.1.0/auto/core/gl/
inflating: glew-2.1.0/auto/core/gl/GL_EXT_texture_array
inflating: glew-2.1.0/auto/core/gl/EGL_VERSION_1_5
2:cmake
wcx@wcx-Ubuntu:~/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY
OPENGL_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindOpenGL.cmake:397 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:40 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/wcx/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild/CMakeFiles/CMakeOutput.log".
报错:Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY
原因:在安装GLEW前一定要先搭建好OpenGL的环境
如果cmake不指定安装位置,这通常会将库文件安装到/usr/local/lib目录,将头文件安装到/usr/local/include/GL目录。
这里指定安装在/usr/local/thirdparty 目录下
wcx@wcx-Ubuntu:~/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/thirdparty ..
CMake Warning (dev) at /usr/share/cmake-3.16/Modules/FindOpenGL.cmake:275 (message):
Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when
available. Run "cmake --help-policy CMP0072" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
FindOpenGL found both a legacy GL library:
OPENGL_gl_LIBRARY: /usr/lib/x86_64-linux-gnu/libGL.so
and GLVND libraries for OpenGL and GLX:
OPENGL_opengl_LIBRARY: /usr/lib/x86_64-linux-gnu/libOpenGL.so
OPENGL_glx_LIBRARY: /usr/lib/x86_64-linux-gnu/libGLX.so
OpenGL_GL_PREFERENCE has not been set to "GLVND" or "LEGACY", so for
compatibility with CMake 3.10 and below the legacy GL library will be used.
Call Stack (most recent call first):
CMakeLists.txt:40 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wcx/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild
3:make
wcx@wcx-Ubuntu:~/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild$ make -j4
Scanning dependencies of target glew_s
Scanning dependencies of target glew
[ 25%] Building C object CMakeFiles/glew.dir/home/wcx/Desktop/thirtypart/glew-2.1.0/src/glew.c.o
[ 25%] Building C object CMakeFiles/glew_s.dir/home/wcx/Desktop/thirtypart/glew-2.1.0/src/glew.c.o
[ 37%] Linking C static library lib/libGLEW.a
[ 50%] Linking C shared library lib/libGLEW.so
[ 50%] Built target glew
Scanning dependencies of target visualinfo
Scanning dependencies of target glewinfo
[ 62%] Building C object CMakeFiles/visualinfo.dir/home/wcx/Desktop/thirtypart/glew-2.1.0/src/visualinfo.c.o
[ 62%] Built target glew_s
[ 75%] Linking C executable bin/visualinfo
[ 75%] Built target visualinfo
[ 87%] Building C object CMakeFiles/glewinfo.dir/home/wcx/Desktop/thirtypart/glew-2.1.0/src/glewinfo.c.o
[100%] Linking C executable bin/glewinfo
[100%] Built target glewinfo
4:install
wcx@wcx-Ubuntu:~/Desktop/thirtypart/glew-2.1.0/build/cmake/testbuild$ sudo make install
[sudo] password for wcx:
[ 25%] Built target glew
[ 50%] Built target visualinfo
[ 75%] Built target glewinfo
[100%] Built target glew_s
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/thirdparty/lib/libGLEW.so.2.1.0
-- Installing: /usr/local/thirdparty/lib/libGLEW.so.2.1
-- Installing: /usr/local/thirdparty/lib/libGLEW.so
-- Installing: /usr/local/thirdparty/lib/libGLEW.a
-- Installing: /usr/local/thirdparty/bin/glewinfo
-- Set runtime path of "/usr/local/thirdparty/bin/glewinfo" to ""
-- Installing: /usr/local/thirdparty/bin/visualinfo
-- Set runtime path of "/usr/local/thirdparty/bin/visualinfo" to ""
-- Installing: /usr/local/thirdparty/lib/pkgconfig/glew.pc
-- Installing: /usr/local/thirdparty/include/GL/wglew.h
-- Installing: /usr/local/thirdparty/include/GL/glew.h
-- Installing: /usr/local/thirdparty/include/GL/glxew.h
-- Installing: /usr/local/thirdparty/lib/cmake/glew/glew-targets.cmake
-- Installing: /usr/local/thirdparty/lib/cmake/glew/glew-targets-release.cmake
-- Installing: /usr/local/thirdparty/lib/cmake/glew/glew-config.cmake
-- Installing: /usr/local/thirdparty/lib/cmake/glew/CopyImportedTargetProperties.cmake