gaoxiang12 / slambook2

edition 2 of the slambook
MIT License
5.3k stars 1.99k forks source link

Ch3 plotTrajectory Cmake can't find epoxy::epoxy build error #311

Closed Uchiha729 closed 1 month ago

Uchiha729 commented 1 month ago
[ 25%] Building CXX object CMakeFiles/coordinateTransform.dir/coordinateTransform.o
[ 50%] Linking CXX executable coordinateTransform
[ 50%] Built target coordinateTransform
[ 75%] Building CXX object CMakeFiles/plotTrajectory.dir/plotTrajectory.o
[100%] Linking CXX executable plotTrajectory
/usr/bin/ld: cannot find -lepoxy::epoxy: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/plotTrajectory.dir/build.make:114: plotTrajectory] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/plotTrajectory.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Initially the error came up saying even -lOpengl::EGL could not be found, but I edited the CMakeLists.txt as shown below

include_directories("/usr/include/eigen3")
add_executable(coordinateTransform coordinateTransform.cpp)

find_package(Pangolin REQUIRED)
find_package(OpenGL REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS})
add_executable(plotTrajectory plotTrajectory.cpp)
target_link_libraries(plotTrajectory ${Pangolin_LIBRARIES})

and the /usr/bin/ld: cannot find -lOpenGL::EGL No such file or directory was gone but still the /usr/bin/ld: cannot find -lepoxy::epoxy: No such file or directory error persists. I also have libepoxy-dev installed through sudo apt-get install libepoxy-dev

JackCao-Git commented 1 month ago

I also encountered the same problem, can you share how to solve the error of epoxy?Even if I have install through sudpo apt-get install libepoxy-dev As shown below, I also edited the CMakeLists.txt and resolved the problem: /usr/bin/ld: can't find -lOpengl::EGL.

cmake_minimum_required( VERSION 2.8 )
project( visualizeGeometry )

set(CMAKE_CXX_FLAGS "-std=c++11")

include_directories( "/usr/include/eigen3" )

find_package( Pangolin )
include_directories( ${Pangolin_INCLUDE_DIRS} )

find_package(OpenGL REQUIRED)

add_executable( visualizeGeometry visualizeGeometry.cpp )
target_link_libraries( visualizeGeometry ${Pangolin_LIBRARIES} )
Uchiha729 commented 1 month ago

You have to add a Findepoxy.cmake module and then use find_package(epoxy REQUIRED) in the CMakeLists.txt and include its directories before generating a target and linking the Pangolin library.

This is the code for Findepoxy.cmake

#[=======================================================================[.rst:
FindEpoxy
---------

Find the Epoxy (*libepoxy*) headers and library.

Imported Targets
^^^^^^^^^^^^^^^^

``epoxy::epoxy``
  The Epoxy library, if found.

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables in your project:

``Epoxy_FOUND``
  true if (the requested version of) Epoxy is available.
``Epoxy_VERSION``
  the version of Epoxy; only defined when a ``pkg-config`` module for
  Epoxy is available.
``Epoxy_LIBRARIES``
  the libraries to link against to use Epoxy.
``Epoxy_INCLUDE_DIRS``
  where to find the Epoxy headers.
``Epoxy_COMPILE_OPTIONS``
  this should be passed to target_compile_options(), if the
  target is not used for linking

#]=======================================================================]

find_package(PkgConfig QUIET)
pkg_check_modules(PC_Epoxy QUIET epoxy)
set(Epoxy_COMPILE_OPTIONS ${PC_Epoxy_CFLAGS_OTHER})
set(Epoxy_VERSION ${PC_Epoxy_VERSION})

find_path(Epoxy_INCLUDE_DIR
    NAMES epoxy/common.h
    HINTS ${PC_Epoxy_INCLUDEDIR} ${PC_Epoxy_INCLUDE_DIR}
)

find_library(Epoxy_LIBRARY
    NAMES ${Epoxy_NAMES} epoxy
    HINTS ${PC_Epoxy_LIBDIR} ${PC_Epoxy_LIBRARY_DIRS}
)

# The libepoxy headers do not have anything usable to detect its version
if ("${Epoxy_FIND_VERSION}" VERSION_GREATER "${Epoxy_VERSION}")
    if (Epoxy_VERSION)
        message(FATAL_ERROR "Required version (${Epoxy_FIND_VERSION}) is"
            " higher than found version (${Epoxy_VERSION})")
    else ()
        message(WARNING "Cannot determine Epoxy version withouit pkg-config")
    endif ()
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Epoxy
    FOUND_VAR Epoxy_FOUND
    REQUIRED_VARS Epoxy_LIBRARY
    VERSION_VAR Epoxy_VERSION
)

if (Epoxy_LIBRARY AND NOT TARGET epoxy::epoxy)
    add_library(epoxy::epoxy UNKNOWN IMPORTED GLOBAL)
    set_target_properties(epoxy::epoxy PROPERTIES
        IMPORTED_LOCATION "${Epoxy_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${Epoxy_COMPILE_OPTIONS}"
        INTERFACE_INCLUDE_DIRECTORIES "${Epoxy_INCLUDE_DIR}"
    )
endif ()

mark_as_advanced(
    Epoxy_LIBRARY
    Epoxy_INCLUDE_DIR
)

if (Epoxy_FOUND)
    set(Epoxy_LIBRARIES ${Epoxy_LIBRARY})
    set(Epoxy_INCLUDE_DIRS ${Epoxy_INCLUDE_DIR})
endif ()

now save this as Findeigen.cmake and add the following lines to CMakeLists.txt

include_directories("/usr/include/eigen3")

find_package(Pangolin REQUIRED)
set(CMAKE_MODULE_PATH "/Path/to/Findeigen.cmake directory")
find_package(epoxy REQUIRED)

include_directories(${Pangolin_INCLUDE_DIRS} ${epoxy_INCLUDE_DIRS})

add_executable(visualizeGeometry visualizeGeometry.cpp)
target_link_libraries(visualizeGeometry ${Pangolin_LIBRARIES})

now try compiling the code after changing the path to Findeigen.cmake file's directory in the CMakeLists.txt

Uchiha729 commented 1 month ago

I also encountered the same problem, can you share how to solve the error of epoxy?Even if I have install through sudpo apt-get install libepoxy-dev As shown below, I also edited the CMakeLists.txt and resolved the problem: /usr/bin/ld: can't find -lOpengl::EGL.

cmake_minimum_required( VERSION 2.8 )
project( visualizeGeometry )

set(CMAKE_CXX_FLAGS "-std=c++11")

include_directories( "/usr/include/eigen3" )

find_package( Pangolin )
include_directories( ${Pangolin_INCLUDE_DIRS} )

find_package(OpenGL REQUIRED)

add_executable( visualizeGeometry visualizeGeometry.cpp )
target_link_libraries( visualizeGeometry ${Pangolin_LIBRARIES} )

Ohh sorry did not see you had error with Opengl. For that just put this in you CMakeLists.txt

cmake_minimum_required( VERSION 2.8 )
project( visualizeGeometry )

set(CMAKE_CXX_FLAGS "-std=c++11")

include_directories( "/usr/include/eigen3" )

find_package( Pangolin )
find_package(OpenGL REQUIRED)
include_directories( ${Pangolin_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS})

add_executable( visualizeGeometry visualizeGeometry.cpp )
target_link_libraries( visualizeGeometry ${Pangolin_LIBRARIES} )

that should sort it out ig

JackCao-Git commented 1 month ago

You have to add a Findepoxy.cmake module and then use find_package(epoxy REQUIRED) in the CMakeLists.txt and include its directories before generating a target and linking the Pangolin library.

This is the code for Findepoxy.cmake

#[=======================================================================[.rst:
FindEpoxy
---------

Find the Epoxy (*libepoxy*) headers and library.

Imported Targets
^^^^^^^^^^^^^^^^

``epoxy::epoxy``
  The Epoxy library, if found.

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables in your project:

``Epoxy_FOUND``
  true if (the requested version of) Epoxy is available.
``Epoxy_VERSION``
  the version of Epoxy; only defined when a ``pkg-config`` module for
  Epoxy is available.
``Epoxy_LIBRARIES``
  the libraries to link against to use Epoxy.
``Epoxy_INCLUDE_DIRS``
  where to find the Epoxy headers.
``Epoxy_COMPILE_OPTIONS``
  this should be passed to target_compile_options(), if the
  target is not used for linking

#]=======================================================================]

find_package(PkgConfig QUIET)
pkg_check_modules(PC_Epoxy QUIET epoxy)
set(Epoxy_COMPILE_OPTIONS ${PC_Epoxy_CFLAGS_OTHER})
set(Epoxy_VERSION ${PC_Epoxy_VERSION})

find_path(Epoxy_INCLUDE_DIR
    NAMES epoxy/common.h
    HINTS ${PC_Epoxy_INCLUDEDIR} ${PC_Epoxy_INCLUDE_DIR}
)

find_library(Epoxy_LIBRARY
    NAMES ${Epoxy_NAMES} epoxy
    HINTS ${PC_Epoxy_LIBDIR} ${PC_Epoxy_LIBRARY_DIRS}
)

# The libepoxy headers do not have anything usable to detect its version
if ("${Epoxy_FIND_VERSION}" VERSION_GREATER "${Epoxy_VERSION}")
    if (Epoxy_VERSION)
        message(FATAL_ERROR "Required version (${Epoxy_FIND_VERSION}) is"
            " higher than found version (${Epoxy_VERSION})")
    else ()
        message(WARNING "Cannot determine Epoxy version withouit pkg-config")
    endif ()
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Epoxy
    FOUND_VAR Epoxy_FOUND
    REQUIRED_VARS Epoxy_LIBRARY
    VERSION_VAR Epoxy_VERSION
)

if (Epoxy_LIBRARY AND NOT TARGET epoxy::epoxy)
    add_library(epoxy::epoxy UNKNOWN IMPORTED GLOBAL)
    set_target_properties(epoxy::epoxy PROPERTIES
        IMPORTED_LOCATION "${Epoxy_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${Epoxy_COMPILE_OPTIONS}"
        INTERFACE_INCLUDE_DIRECTORIES "${Epoxy_INCLUDE_DIR}"
    )
endif ()

mark_as_advanced(
    Epoxy_LIBRARY
    Epoxy_INCLUDE_DIR
)

if (Epoxy_FOUND)
    set(Epoxy_LIBRARIES ${Epoxy_LIBRARY})
    set(Epoxy_INCLUDE_DIRS ${Epoxy_INCLUDE_DIR})
endif ()

now save this as Findeigen.cmake and add the following lines to CMakeLists.txt

include_directories("/usr/include/eigen3")

find_package(Pangolin REQUIRED)
set(CMAKE_MODULE_PATH "/Path/to/Findeigen.cmake directory")
find_package(epoxy REQUIRED)

include_directories(${Pangolin_INCLUDE_DIRS} ${epoxy_INCLUDE_DIRS})

add_executable(visualizeGeometry visualizeGeometry.cpp)
target_link_libraries(visualizeGeometry ${Pangolin_LIBRARIES})

now try compiling the code after changing the path to Findeigen.cmake file's directory in the CMakeLists.txt

Thank you very much for providing the code of FindEpoxy.cmake. It's critical.