在 Linux 上尝试 运行 OpenGL SuperBible 示例代码时出现“对 'glfwOpenWindowHint' 的未定义引用”错误
Getting `undefined reference to 'glfwOpenWindowHint' ` error when trying to run OpenGL SuperBible example code on Linux
我第一次尝试在我的 Manjaro(arch)系统上运行 OpenGL SuperBible 第 6 版示例代码。
我按照 HOWTOBUILD.txt,通过 pacman 安装了 mesa 和 glfw(glfw-wayland,不确定是否有区别)。第一次尝试运行不成功,然后改成CMakeList.txt中的错误,如这里所述
它摆脱了 undefined reference to 'glfwInit'
错误,但所有其他未定义的错误仍然存在。谁能帮我无误地编译这个?
代码示例:
https://github.com/openglsuperbible/sb6code
当我尝试 运行 make
时完全错误:
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x8b): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xa1): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xb0): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xbf): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xd5): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o:wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xf5): more undefined references to `glfwOpenWindowHint' follow
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x133): undefined reference to `glfwGetDesktopMode'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x18b): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x1e9): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x25b): undefined reference to `glfwSetMousePosCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x267): undefined reference to `glfwSetMouseWheelCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x280): undefined reference to `glfwEnable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x289): undefined reference to `glfwDisable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x29a): undefined reference to `glfwGetWindowParam'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x3bc): undefined reference to `glfwGetWindowParam'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/wrapmodes.dir/build.make:105: bin/wrapmodes] Error 1
make[1]: *** [CMakeFiles/Makefile2:296: CMakeFiles/wrapmodes.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
我下载了源代码并尝试了您完成的步骤,不出所料,收到了同样的错误消息。
而且源代码似乎使用了 GLFW2 而不是 GLFW3。
glfwOpenWindowHint
在 GLFW3
中重命名为 glfwWindowHint
参见:glfwOpenWindowHint not declared in this scope GLFW3 & GLEW
您可以尝试安装 GLFW2 并再次 运行。由于 GLFW2 在 Ubuntu Xenial 中可用,请记住相应地配置 sources.list
。
对于 OpenGL SuperBible 第 6 期
编辑:
我无法从 Ubuntu Xenial 存储库安装 libglfw2
。并从官方网站手动安装dpkg
。
从 https://launchpad.net/ubuntu/xenial/+package/libglfw-dev
下载 .deb
文件
转到文件夹 .deb
安装在 运行 sudo dpkg -i [name of libglfw2].deb
运行 find . -name "libglfw*"
在/usr/lib
中找到库的路径。 (可以有多个 libglfw.so
因为你已经下载 GLFW3
所以要小心)
为刚刚安装的动态库创建一个符号link,方法是运行执行以下命令:
sudo ln -s /usr/lib/[path to file]/[filename] /usr/lib/[path to file]/libglfw2.so
编辑sb6code/CMakeFiles/tunnel.dir/link.txt
如下
-lglfw
至 -lglfw2
运行 make
对于 OpenGL SuperBible 第 7 期
如果您已经安装了 libglfw3
但无法安装 运行 cmake ..
,这可能是因为您的 libglfw3.so
存储为 libglfw.so
。
在这种情况下,您可以为它创建一个符号 link:
sudo ln -s /usr/lib/[path to file]/[libglfw name].so /usr/lib/[path to file]/libglfw3.so
保存并在 build
.
中再次 运行 cmake ..
如果由于 linker 而失败,请确保您拥有所有依赖项:
libglfw3-dev libx11-dev libxrandr-dev libxinerama-dev libxi-dev libxxf86vm-dev libxcursor-dev
我第一次尝试在我的 Manjaro(arch)系统上运行 OpenGL SuperBible 第 6 版示例代码。
我按照 HOWTOBUILD.txt,通过 pacman 安装了 mesa 和 glfw(glfw-wayland,不确定是否有区别)。第一次尝试运行不成功,然后改成CMakeList.txt中的错误,如这里所述
它摆脱了 undefined reference to 'glfwInit'
错误,但所有其他未定义的错误仍然存在。谁能帮我无误地编译这个?
代码示例: https://github.com/openglsuperbible/sb6code
当我尝试 运行 make
时完全错误:
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x8b): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xa1): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xb0): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xbf): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xd5): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o:wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xf5): more undefined references to `glfwOpenWindowHint' follow
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x133): undefined reference to `glfwGetDesktopMode'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x18b): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x1e9): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x25b): undefined reference to `glfwSetMousePosCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x267): undefined reference to `glfwSetMouseWheelCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x280): undefined reference to `glfwEnable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x289): undefined reference to `glfwDisable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x29a): undefined reference to `glfwGetWindowParam'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x3bc): undefined reference to `glfwGetWindowParam'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/wrapmodes.dir/build.make:105: bin/wrapmodes] Error 1
make[1]: *** [CMakeFiles/Makefile2:296: CMakeFiles/wrapmodes.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
我下载了源代码并尝试了您完成的步骤,不出所料,收到了同样的错误消息。
而且源代码似乎使用了 GLFW2 而不是 GLFW3。
glfwOpenWindowHint
在 GLFW3
glfwWindowHint
参见:glfwOpenWindowHint not declared in this scope GLFW3 & GLEW
您可以尝试安装 GLFW2 并再次 运行。由于 GLFW2 在 Ubuntu Xenial 中可用,请记住相应地配置 sources.list
。
对于 OpenGL SuperBible 第 6 期
编辑:
我无法从 Ubuntu Xenial 存储库安装 libglfw2
。并从官方网站手动安装dpkg
。
从 https://launchpad.net/ubuntu/xenial/+package/libglfw-dev
下载.deb
文件转到文件夹
.deb
安装在 运行sudo dpkg -i [name of libglfw2].deb
运行
find . -name "libglfw*"
在/usr/lib
中找到库的路径。 (可以有多个libglfw.so
因为你已经下载GLFW3
所以要小心)为刚刚安装的动态库创建一个符号link,方法是运行执行以下命令:
sudo ln -s /usr/lib/[path to file]/[filename] /usr/lib/[path to file]/libglfw2.so
编辑
sb6code/CMakeFiles/tunnel.dir/link.txt
如下-lglfw
至-lglfw2
运行
make
对于 OpenGL SuperBible 第 7 期
如果您已经安装了 libglfw3
但无法安装 运行 cmake ..
,这可能是因为您的 libglfw3.so
存储为 libglfw.so
。
在这种情况下,您可以为它创建一个符号 link:
sudo ln -s /usr/lib/[path to file]/[libglfw name].so /usr/lib/[path to file]/libglfw3.so
保存并在 build
.
cmake ..
如果由于 linker 而失败,请确保您拥有所有依赖项:
libglfw3-dev libx11-dev libxrandr-dev libxinerama-dev libxi-dev libxxf86vm-dev libxcursor-dev