当前位置: 首页 > 知识库问答 >
问题:

CMake,glfw:包含X11,但未找到“xConvertSelection”

闾丘昊然
2023-03-14

/usr/bin/ld://usr/local/lib/libglfw3.a(x11_windod.co):对符号“xconvertselection”的未定义引用/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../../x86_64-linux-gnu/4.8/.so:添加符号错误:命令行中缺少DSOcollect2:错误:ld返回1退出状态

XConvertSelection似乎来自X11,但我已经包含并链接到X11,如下所示。如果X11已经被包括和链接,为什么没有找到这个项目?

===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

共有1个答案

符畅
2023-03-14

在深入研究这个问题并与链接顺序进行了几个小时的斗争后,我有以下内容:

===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 !

这个确切的设置可能在Linux系统上不是通用的,但我认为它可能会帮助某人找到一个成功的链接顺序。

 类似资料:
  • 我正在尝试用MinGW编译器用CMake构建PODOFO库。它需要一些外部库,如zlib、jpeg、openssl和freetype。我的cmake命令如下: cmake-g“mingw makefiles”_path=c:\users\abhishek\downloads\openSSL-0.9.8h-1-lib\lib-dpodofo_build_shared:bool=false.. 不知何

  • 我创建了一个应用程序,创建gpx文件。除了分享,一切都很好。因此,我创建了一个文件提供程序。你可以在下面看到它的配置。提供商在运行Android8.0.0的Android设备上工作正常,但在朋友华为(6.0)上不工作 清单中的提供者: 文件路径。xml: 代码中的用法: 我希望有人能帮我找到导致应用程序在某些设备上崩溃的错误...

  • 问题内容: 我试图用cmake建立一个项目。这个项目正在使用Java等。问题是在代码处 我收到以下错误: 虽然 输出 怎么会?该错误的原因是什么? 问题答案: 如果您使用的是Linux操作系统,则必须将Java home设置为export

  • 我使用phpUnit与cakephp进行测试,但当我试图运行一些测试类抛出一个致命错误,但这个类插入正确,甚至没有被指控丢失文件错误的PHPStorm。 执行测试用例的命令: C:\xampp\htdocs\PROJETOS\购物\供应商\phpUnit 致命错误: 致命错误:在第12行的C:\xampp\htdocs\PROJET OS\Shopping\tests\TestCase\Model

  • 我知道关于这个问题有很多问题。我尝试了大约10种不同的方法,但都没有成功。我总是会遇到下一个错误: 官方教程也没有帮助。我将在下面分享我的代码,也许我做错了什么,你知道这里到底出了什么问题。。 清单: provider_paths.xml 我将文件保存到: 文件路径的示例:file:///storage/emulated/0/Android/data/app.kwork/files/IMG-afb

  • 我有一个与package2有依赖关系的package1。 下面是包2的pom.xml 在pom.xml包1中 运行和后,包2的jar文件存在于~/。m2/存储库和包1能够找到它。但是,在包1中,当我尝试导入时 没有找到包,但令人惊讶的是IntelliJ能够在com下找到类。公司数据 例如,IntelliJ发现了com。公司数据A和com。公司数据B,但不是com。公司数据,我很困惑。