GLFW - Linker Errors on UBuntu 14.04 LTS

I want to compile the sample code from this site (below). I downloaded the source code for GLFW 3.0.4 and I built it in a custom location. I used the default settings, and GLFW was created as a static library. My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)
project(glfw_test_project)

SET(CMAKE_CXX_FLAGS "-Wall -Werror -g -std=c++11")

find_package(OpenGL REQUIRED)

include_directories(/home/user/MyLibs/OpenGL/glfw-3.0.4/include)
link_directories(/home/user/MyLibs/OpenGL/glfw-3.0.4/build/src)

add_executable(glfw_test main.cpp)

target_link_libraries(glfw_test ${OPENGL_gl_LIBRARY})
target_link_libraries(glfw_test glfw3)

When I run make , I get the following information:

Linking CXX executable glfw_test
/usr/bin/ld: /home/user/MyLibs/OpenGL/glfw-3.0.4/build/src/libglfw3.a(x11_clipboard.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [glfw_test] Error 1
make[1]: *** [CMakeFiles/glfw_test.dir/all] Error 2
make: *** [all] Error 2

What's wrong?

Edit1 When I build GLFW as a dynamic library, everything works fine. Then the last line in my CMakeLists.txt needs to be replaced with:

target_link_libraries(glfw_test glfw)

What is wrong with using a static library?

+4
source share
2

Ubuntu 14.04 LTS.

: error adding symbols: DSO missing from command line . . $ make VERBOSE=1, . : TARGET_LINK_LIBRARIES() CMakeLists.txt .

: GLFW3, X11 , . GLFW-Documentation cmake, : ${GLFW_STATIC_LIBRARIES}. , pkg-config X11 libs:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(myProject)

FIND_PACKAGE( PkgConfig REQUIRED )
pkg_search_module( GLFW3 REQUIRED glfw3 ) # sets GLFW3 as prefix for glfw vars

# now ${GLFW3_INCLUDE_DIR}, ${GLFW3_LIBRARIES} and ${GLFW3_STATIC_LIBRARIES} 
# are set

INCLUDE_DIRECTORIES( ${GLFW3_INCLUDE_DIR} )
ADD_EXECUTABLE( myProject mySource.cpp )

TARGET_LINK_LIBRARIES( myProject ${GLFW_STATIC_LIBRARIES} )
# they include X11 libs

lib $ make VERBOSE=1, X11-: -lXrandr -lXi -lXrender -ldrm -lXdamage -lXxf86vm -lXext -lX11 -lpthread.

-: , X11 .. . X11 lib . : TARGET_LINK_LIBRARIES( myProject ${GLFW_LIBRARIES} )

: , glfwCommands undefined reference to - . , GLFW3 /usr/local/lib, ​​ LD_LIBRARY_PATH, ​​ /usr/lib32. -L/usr/local/lib . , LD_LIBRARY_PATH=/usr/lib32;/usr/local/lib;.

:, , cmake GLFW, :

FOREACH(item ${GLFW3_STATIC_LIBRARIES})
    MESSAGE(STATUS "  using lib: " ${item})
ENDFOREACH()
+5

, , GLFW . , , .

, libglfw3.a, X11. , , - , CMake , . libglfw.so, X11 , CMake , .

, . .pc GLFW, , , :

pkg-config --static --libs x11 xrandr xi xxf86vm gl

CMake, :

target_link_libraries( glfw_test glfw3 Xrandr Xrender Xi GL m dl drm Xdamage X11-xcb xcb-glx xcb-dri2 xcb-dri3 xcb-present xcb-sync xshmfence Xxf86vm Xfixes Xext X11 pthread xcb Xau Xdmcp)

, CMakeLists.txt, .

, X11 CMake :

find_package(X11 REQUIRED)
target_link_libraries( my_program ${X11_LIBRARIES} )

, X11_LIBRARIES, , GLFW.

, / CMake, , .

+2

Source: https://habr.com/ru/post/1545506/


All Articles