glfw的编译

关于glfw在编译过程中,遇到过很多问题,这里简单记录一下。

1.下载源码

git clone https://github.com/glfw/glfw.git

2.安装X11

yum search的时候你会发现有很多,这里选择libx11-devel.i686还是libx11-devel.x86_64,这点很重要,因为如果和你的机器不匹配会导致编译不过。

[root@localhost glfw-build]# yum search X11
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirror.bit.edu.cn
 * updates: mirror01.idc.hinet.net
=============================== N/S matched: X11 ===============================
dbus-x11.x86_64 : X11-requiring add-ons for D-BUS
libX11.i686 : Core X11 protocol client library
libX11.x86_64 : Core X11 protocol client library
libX11-common.noarch : Common data for libX11
libX11-devel.i686 : Development files for libX11
libX11-devel.x86_64 : Development files for libX11

然后使用命令安装X11,

yum install -y libX11-devel.x86_64

看官网明确说是依赖X11,这里安装完X11,那么就应该编译成功,实则不然。

报错:

[root@localhost glfw-build]# cmake ..
-- Using X11 for window creation
-- Looking for XOpenDisplay in /usr/lib/libX11.so
-- Looking for XOpenDisplay in /usr/lib/libX11.so - not found
-- Looking for dnet_ntoa in dnet
-- Looking for dnet_ntoa in dnet - not found
-- Looking for dnet_ntoa in dnet_stub
-- Looking for dnet_ntoa in dnet_stub - not found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Found X11: /usr/lib/libX11.so
CMake Error at CMakeLists.txt:210 (message):
  The RandR headers were not found

3.安装其他依赖的库(以我自己为例)

      3.1缺少The RandR headers were not found

[root@localhost glfw-build]# yum search RandR
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
============================== N/S matched: RandR ==============================
libXrandr.i686 : X.Org X11 libXrandr runtime library
libXrandr.x86_64 : X.Org X11 libXrandr runtime library
libXrandr-devel.i686 : X.Org X11 libXrandr development package
libXrandr-devel.x86_64 : X.Org X11 libXrandr development package

  名称和简介匹配 only,使用“search all”试试。
[root@localhost glfw-build]# yum search libXrandr-devel.i686


       3.2 缺少The Xinerama headers were not found

[root@localhost glfw-build]# yum search Xinerama
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror01.idc.hinet.net
============================ N/S matched: Xinerama =============================
libXinerama.i686 : X.Org X11 libXinerama runtime library
libXinerama.x86_64 : X.Org X11 libXinerama runtime library
libXinerama-devel.i686 : X.Org X11 libXinerama development package
libXinerama-devel.x86_64 : X.Org X11 libXinerama development package

  名称和简介匹配 only,使用“search all”试试。
[root@localhost glfw-build]# yum install libXinerama-devel.i686

     3.3 缺少The Xcursor headers were not found

[root@localhost glfw-build]# yum search Xcursor
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror01.idc.hinet.net
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror01.idc.hinet.net
============================= N/S matched: Xcursor =============================
libXcursor-devel.i686 : Development files for libXcursor
libXcursor-devel.x86_64 : Development files for libXcursor
libXcursor.x86_64 : Cursor management library
libXcursor.i686 : Cursor management library

  名称和简介匹配 only,使用“search all”试试。
[root@localhost glfw-build]# yum install libXcursor-devel.i686

      3.4 缺少 The XInput headers were not found

[root@localhost glfw-build]# yum search libxi-dev
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
============================ N/S matched: libxi-dev ============================
libXi-devel.i686 : X.Org X11 libXi development package
libXi-devel.x86_64 : X.Org X11 libXi development package

  名称和简介匹配 only,使用“search all”试试。
[root@localhost glfw-build]# yum install libXi-devel.x86_64

4.编译glfw

cmake -DBUILD_SHARED_LIBS=ON .. 或则 cmake .. (分别生成动态库和静态库 )

make && make install

你可能感兴趣的:(编程杂谈)