robotology / osqp-eigen

Simple Eigen-C++ wrapper for OSQP library
https://robotology.github.io/osqp-eigen/
BSD 3-Clause "New" or "Revised" License
395 stars 118 forks source link

error while loading shared libraries: libosqp.so #150

Open Julius-ZCJ opened 1 year ago

Julius-ZCJ commented 1 year ago

Hello, developer: I get this error:error while loading shared libraries: libosqp.so: cannot open shared object file: No such file or directory

This is my cmakelist.txt:

cmake_minimum_required(VERSION 3.23)
project(learn_ws)

set(CMAKE_CXX_STANDARD 17)

find_package(Eigen3 REQUIRED)
find_package(osqp REQUIRED)
find_package(OsqpEigen REQUIRED)

set(SOURCES
        ${CMAKE_CURRENT_SOURCE_DIR}/src/eigen_learning.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/osqp_learning.cpp
    )
set(HEADERS
        ${CMAKE_CURRENT_SOURCE_DIR}/include/eigen_learning.h
        ${CMAKE_CURRENT_SOURCE_DIR}/include/osqp_learning.h
)

include_directories(
        include
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)
include_directories(${EIGEN3_INCLUDE_DIR})

add_executable(learn_ws main.cpp  ${HEADERS} ${SOURCES})
target_link_libraries(learn_ws
        osqp         #####链接osqp库,因为OsqpEigen需要osqp库
        OsqpEigen    #####链接OsqpEigen库
#        /usr/local/lib/libOsqpEigen.so
#        /usr/local/lib/libosqp.so
)

but when I add "/usr/local/lib/libosqp.so" in target_link_libraries, this error is fix, I want to know why, and how to use this lib just need add code " find_package(osqp REQUIRED)" in cmakelist.txt, rather than "/usr/local/lib/libosqp.so"

siddharthdeore commented 12 months ago

@Julius-ZCJ, I recommend updating the target_link_libraries section in your CMakeLists.txt file as follows:

target_link_libraries(learn_ws PUBLIC OsqpEigen::OsqpEigen)
traversaro commented 12 months ago

Indeed, @Julius-ZCJ can you try @siddharthdeore fix? Thanks!

traversaro commented 11 months ago

@Julius-ZCJ did you tried the proposed fix? Thanks!