简体   繁体   English

CMake,GLFW:包括X11,但未找到“ XConvertSelection”

[英]CMake , GLFW: X11 Included but 'XConvertSelection' Not Found

Ubuntu 14.04 , GLFW 3.2.1 , OpenGL 4.5.0 NVIDIA 367.57 Ubuntu 14.04,GLFW 3.2.1,OpenGL 4.5.0 NVIDIA 367.57

I am trying to build the "Hello Triangle" OpenGL Example found at http://antongerdelan.net/opengl/hellotriangle.html but I am running into trouble. 我正在尝试构建http://antongerdelan.net/opengl/hellotriangle.html上的“ Hello Triangle” OpenGL示例,但我遇到了麻烦。 I downloaded the GLFW source and built out-of-source and installed with no extra flags or options. 我下载了GLFW源,并进行了源外构建,并安装时没有额外的标志或选项。

Below is the src/CMakeLists.txt file for Hello Triangle that is assembled from both the GLFW and from SO answers. 以下是Hello Triangle的src/CMakeLists.txt文件,它是从GLFW和SO答案组装而成的。 After wrestling with linking order for a bit, the build process only gives me one error: 在尝试了一点连接顺序之后,构建过程只给了我一个错误:

/usr/bin/ld: //usr/local/lib/libglfw3.a(x11_window.co): undefined reference to symbol 'XConvertSelection' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status /usr/bin/ld: //usr/local/lib/libglfw3.a(x11_window.co): undefined reference to symbol 'XConvertSelection' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

XConvertSelection appears to come from X11, but I have included and linked to X11, as shown below. XConvertSelection似乎来自X11,但是我已经包含并链接到X11,如下所示。 Why is this item not found if X11 has been included and linked? 如果已经包含并链接了X11,为什么找不到此项目?

=== src/CMakeLists.txt === === src / CMakeLists.txt ===

# SOURCE CMAKELISTS

cmake_minimum_required( VERSION 2.6 )
project( HelloTriangle )

# ~ Special Libraries ~

# First you need to find the PkgConfig package. If this fails, you may need to install the pkg-config package for your distribution.
find_package(PkgConfig REQUIRED)

find_package(X11 REQUIRED)
if(NOT X11_FOUND)
    message("ERROR: x11 not found")
endif(NOT X11_FOUND)

# Note that the dependencies do not include OpenGL or GLU, as GLFW loads any OpenGL, OpenGL ES or Vulkan libraries it needs at runtime and does not use GLU. If your application calls OpenGL directly, instead of using a modern extension loader library you can find it by requiring the OpenGL package.
find_package(OpenGL REQUIRED)
if(NOT OPENGL_FOUND)
    message("ERROR: OpenGL not found")
endif(NOT OPENGL_FOUND)

# With just a few changes to your CMakeLists.txt, you can locate the package and target files generated when GLFW is installed.
find_package(glfw3 3.2 REQUIRED)

# This creates the CMake commands to find pkg-config packages. Then you need to find the GLFW package.
pkg_search_module(GLFW REQUIRED glfw3)

include_directories(${X11_INCLUDE_DIR})

# This creates the CMake variables you need to use GLFW. To be able to include the GLFW header, you need to tell your compiler where it is.
include_directories(${GLFW_INCLUDE_DIRS})

# After everything is included, add the executable so that we can link
add_executable( HelloTriangle hello_triangle.cpp )

target_link_libraries(HelloTriangle ${X11_LIBRARIES})

# Seems like a similar issue: http://stackoverflow.com/questions/14772681/c-compile-error-when-includeing-irrlicht-static-lib
target_link_libraries(HelloTriangle /usr/lib/x86_64-linux-gnu/libX11.so)
target_link_libraries(HelloTriangle /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1)
# target_link_libraries(HelloTriangle /usr/lib/x86_64-linux-gnu/libXxf86vm.so)

# If OpenGL is found, the OPENGL_FOUND variable is true and the OPENGL_INCLUDE_DIR and OPENGL_gl_LIBRARY cache variables can be used.
target_include_directories(HelloTriangle PUBLIC ${OPENGL_INCLUDE_DIR})

target_link_libraries(HelloTriangle ${OPENGL_gl_LIBRARY})

target_link_libraries(HelloTriangle ${GL_LIBRARY})

# The OpenGL CMake package also looks for GLU. If GLU is found, the OPENGL_GLU_FOUND variable is true and the OPENGL_INCLUDE_DIR and OPENGL_glu_LIBRARY cache variables can be used.
target_link_libraries(HelloTriangle ${OPENGL_glu_LIBRARY})

# You also need to link against the correct libraries. If you are using the shared library version of GLFW, use the GLFW_LIBRARIES variable.
target_link_libraries(HelloTriangle ${GLFW_LIBRARIES}) # DYNAMIC: Does not find: XConvertSelection
# If you are using the static library version of GLFW, use the GLFW_STATIC_LIBRARIES variable instead.
# target_link_libraries(HelloTriangle ${GLFW_STATIC_LIBRARIES}) # STATIC: Does not find: glewExperimental , glewInit

After digging even further into SO and wrestling with linking order for several hours, I have the following: 在深入研究SO并通过链接顺序进行了几个小时的研究后,我得到了以下内容:

=== src/CMakeLists.txt === === src / CMakeLists.txt ===

# SOURCE CMAKELISTS

cmake_minimum_required( VERSION 2.6 )
project( HelloTriangle )

# ~ Special Libraries ~
find_package(PkgConfig REQUIRED) # First you need to find the PkgConfig package

find_package(X11 REQUIRED) # Make sure x is there 
if(NOT X11_FOUND)
    message("ERROR: x11 not found")
endif(NOT X11_FOUND)

find_package(OpenGL REQUIRED) # Make sure OpenGL is available for direct calls
if(NOT OPENGL_FOUND)
    message("ERROR: OpenGL not found")
endif(NOT OPENGL_FOUND)

find_package(glfw3 3.2 REQUIRED) # locate the package and target files generated when GLFW is installed.

pkg_search_module(GLFW REQUIRED glfw3) # CMake commands to find pkg-config packages

include_directories(${GLFW_INCLUDE_DIRS}) # creates the CMake variables you need to use GLFW.
include_directories(${X11_INCLUDE_DIR}) # Get all the x stuff

add_executable( HelloTriangle hello_triangle.cpp ) # After everything is included, add the executable 

target_include_directories(HelloTriangle PUBLIC ${OPENGL_INCLUDE_DIR}) # Obviously

target_link_libraries(HelloTriangle ${GLFW_LIBRARIES}) # If using the shared library, GLFW_LIBRARIES
# target_link_libraries(HelloTriangle ${GLFW_STATIC_LIBRARIES}) # If using the static library, GLFW_STATIC_LIBRARIES
target_link_libraries(HelloTriangle ${OPENGL_gl_LIBRARY}) # More OpenGL stuff I guess?
target_link_libraries(HelloTriangle ${GL_LIBRARY})
target_link_libraries(HelloTriangle ${OPENGL_glu_LIBRARY}) # The OpenGL CMake package also looks for GLU.
# http://stackoverflow.com/questions/23171894/cant-compile-easy-source-in-c-and-opengl-glfw-in-linux-in-netbeans
target_link_libraries(HelloTriangle GLEW m dl Xinerama Xrandr Xi Xcursor pthread) # GLFW misses this stuff!
# Seems like a similar issue: http://stackoverflow.com/questions/14772681/c-compile-error-when-includeing-irrlicht-static-lib
target_link_libraries(HelloTriangle /usr/lib/x86_64-linux-gnu/libX11.so) # x11 linking misses this stuff!
target_link_libraries(HelloTriangle /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1)
target_link_libraries(HelloTriangle ${X11_LIBRARIES}) # x11 !

This exact setup may not be universal on Linux systems, but I thought it might help someone work out a successful linking order. 这种精确的设置在Linux系统上可能不是通用的,但我认为它可以帮助某人制定成功的链接顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM