首页 > 解决方案 > /usr/bin/ld: ../freeglut/libfreeglut_static.a(freeglut_state.o): 未定义对 Box2d 中符号“XGetWindowAttributes”的引用

问题描述

我遵循了这个,它向我展示了安装步骤。
我以前安装了依赖项。
unzip Box2D_v2.1.2.zip cd Box2D_v2.1.2/Box2D/Build cmake .. make

在 make 的最后一步,我收到以下消息。
/usr/bin/ld: ../freeglut/libfreeglut_static.a(freeglut_state.o): undefined reference to symbol 'XGetWindowAttributes' //usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
我在网上搜索了每个人都说用-X11标志编译,但这是一个 make 文件,我不太关心

标签: linuxcmakebox2dx11

解决方案


出现此错误是因为未为 Linux 配置CMakeLists.txt文件。Testbed

要解决此问题,请打开文件Box2D_v2.1.2/Box2D/Testbed/CMakeLists.txt并相应地更改以下行。

由此:

if(APPLE)
         # We are not using the Apple's framework version, but X11's
         include_directories( /usr/X11/include )
         link_directories( /usr/X11/lib )
         set (OPENGL_LIBRARIES GL GLU GLUT X11)
endif(APPLE)

对此:

if(UNIX)
        # We are not using the Apple's framework version, but X11's
        include_directories( /usr/X11/include )
        link_directories( /usr/X11/lib )
        set (OPENGL_LIBRARIES GL GLU X11)
endif(UNIX)

这对我有用。


推荐阅读