borglab / gtsam

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.
http://gtsam.org
Other
2.63k stars 769 forks source link

libmetis-gtsam issue #380

Closed linzha0 closed 4 years ago

linzha0 commented 4 years ago

Hi, I am in Ubuntu 20.04 and built gtsam follow the quick start and build the github branch successfully with a install path.

Then I try to build the OdometryExample.cpp with cmake(with ROS but plain gtsam). The CMakeLists.txt is shown below. The build was successfully, too.

cmake_minimum_required(VERSION 3.0.2)
project(sidescan_slam)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

### GTSAM 
set(GTSAM_DIR /home/lin/develop/3rd/gtsam/install/lib/cmake/GTSAM)
find_package(GTSAM)
if(GTSAM_FOUND)  
  message(STATUS "Found GTSAM ${GTSAM_VERSION}")
else()
  message(STATUS "GTSAM Not Found")
endif()

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package()

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${GTSAM_INCLUDE_DIR}
)

link_directories(
    ${GTSAM_LIBRARY_DIRS}
)

### build test
add_executable(T_GTSAM_odomTest test/OdometryExample.cpp)
target_link_libraries(T_GTSAM_odomTest gtsam)

Then I run the executable, got the error:

./T_GTSAM_odomTest: error while loading shared libraries: libmetis-gtsam.so: cannot open shared object file: No such file or directory

Any suggestions? Thank you so much!

acxz commented 4 years ago

@CrazyPopLin Hmm that is odd indeed. I got OdometryExample compiling as follows.

  1. Install gtsam as specified in the quick start
  2. Create the following structure:
    test-gtsam
    ├── build
    ├── CMakeLists.txt
    └── OdometryExample.cpp
  3. Populate OdometryExample.cpp as an exact copy from https://github.com/borglab/gtsam/blob/develop/examples/OdometryExample.cpp
  4. Populate CMakeLists.txt as follows:
    
    project(OdometryExample)
    cmake_minimum_required(VERSION 2.8)

find_package(GTSAM REQUIRED)

include_directories(${GTSAM_INCLUDE_DIR})

add_executable(OdometryExample OdometryExample.cpp) target_link_libraries(OdometryExample gtsam)


5. Build and run the project

cd build cmake .. make ./OdometryExample


Please let us know if the following doesn't work for you. (Let's make sure we get OdometryExample working by itself before we try linking it with ROS catkin packages)

Also I do not think you need the following:

link_directories( ${GTSAM_LIBRARY_DIRS} )



And you should be linking `${catkin_LIBRARIES}` as well:
`target_link_libraries(T_GTSAM_odomTest gtsam ${catkin_LIBRARIES})`

Also consider populating the arguments for `catkin_package()` as recommended by ROS: http://wiki.ros.org/catkin/CMakeLists.txt#catkin_package.28.29
linzha0 commented 4 years ago

hi @acxz ,thanks for your reply. I did just like the quick start but installed the gtsam a self-defined path, so this time the pure CMakeLists.txt (without ROS env) like below:

project(test_gtsam)
cmake_minimum_required(VERSION 2.8)

### GTSAM 
set(GTSAM_DIR /home/lin/develop/3rd/gtsam/install/lib/cmake/GTSAM)
find_package(GTSAM)
if(GTSAM_FOUND)  
  message(STATUS "Found GTSAM ${GTSAM_VERSION}")
else()
  message(STATUS "GTSAM Not Found")
endif()

include_directories(${GTSAM_INCLUDE_DIR})

add_executable(OdometryExample OdometryExample.cpp)
target_link_libraries(OdometryExample gtsam)

Same issue occurred. Maybe I used Ubuntu 20.04, because this system not tested according Important Installation Notes?

acxz commented 4 years ago

did just like the quick start but installed the gtsam a self-defined path

Can you give the exact commands you followed? Without them I am afraid I cannot reproduce your situation and therefore have limited knowledge in helping you.

because this system not tested according Important Installation Notes?

That list sort of outdated anyways tbh. I'm running on Arch Linux with GCC 10.1.0. People that I know use GTSAM on Ubuntu 20.04 as well so it is not a system issue.

Also just to make sure, that local install is the only installation of GTSAM you have on your system right? If not can you ensure that.

linzha0 commented 4 years ago

The install commands shown below:

$ cd <my_path>/
$ git clone https://github.com/borglab/gtsam
$ cd gtsam
$ mkdir build && mkdir install
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=<my_path>/gtsam/install ..
$ make check
$ install

The gtsam test project build steps are just like your suggestion. This is new installed system, and it's first to install gtsam. Please let me know if you have any questions. thanks for your help.

acxz commented 4 years ago

And how did you compile your own project?

linzha0 commented 4 years ago

gtsam_issue The gtsam test project build steps are just like your suggestion.

acxz commented 4 years ago

The gtsam test project build steps are just like your suggestion.

Weird those instructions shouldn't even compile your project if GTSAM is installed locally.

After installing GTSAM to a local directory, I built my project with the following commands:

cd build
cmake .. -DCMAKE_PREFIX_PATH=~/local
make

and just to iterate, where I installed GTSAM locally as follows after cloning:

cd gtsam
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/local
make install

With these steps I still do not receive the libmetis-gtsam issue. Can you try these exact steps and let me know the output of them?

linzha0 commented 4 years ago

Build gtsam

$ cd 
$ mkdir local
$ cd local
$ git clone https://github.com/borglab/gtsam
$ cd gtsam
$ mkdir build 
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/local
$ make install

The CMake output for building gtsam:

-- The CXX compiler identification is GNU 9.3.0 -- The C compiler identification is GNU 9.3.0 -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- GTSAM_SOURCE_ROOT_DIR: [/home/lin/local/gtsam] -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.43") found components: serialization system filesystem thread program_options date_time timer chrono regex -- Found TBB: /usr/include (found suitable version "2020.1", minimum required is "4.4") found components: tbb tbbmalloc -- Could NOT find MKL (missing: MKL_INCLUDE_DIR MKL_LIBRARIES) -- Found OpenMP_C: -fopenmp (found version "4.5") -- Found OpenMP_CXX: -fopenmp (found version "4.5") -- Found OpenMP: TRUE (found version "4.5")
-- Found Eigen version: 3.3.7 -- Building 3rdparty -- Looking for execinfo.h -- Looking for execinfo.h - found -- Looking for getline -- Looking for getline - found -- checking for thread-local storage - found -- Could NOT find GeographicLib (missing: GeographicLib_LIBRARY_DIRS GeographicLib_LIBRARIES GeographicLib_INCLUDE_DIRS) -- Building base -- Building geometry -- Building inference -- Building symbolic -- Building discrete -- Building linear -- Building nonlinear -- Building sam -- Building sfm -- Building slam -- Building smart -- Building navigation -- GTSAM Version: 4.0.2 -- Install prefix: /home/lin/local -- Building GTSAM - shared: ON -- Building base_unstable -- Building geometry_unstable -- Building linear_unstable -- Building discrete_unstable -- Building dynamics_unstable -- Building nonlinear_unstable -- Building slam_unstable -- Building partition_unstable -- GTSAM_UNSTABLE Version: 4.0.2 -- Install prefix: /home/lin/local -- Wrote /home/lin/local/gtsam/build/GTSAMConfig.cmake -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- =============================================================== -- ================ Configuration Options ====================== -- CMAKE_CXX_COMPILER_ID type : GNU -- CMAKE_CXX_COMPILER_VERSION : 9.3.0 -- CMake version : 3.16.3 -- CMake generator : Unix Makefiles -- CMake build tool : /usr/bin/make -- Build flags
-- Build Tests : Enabled -- Build examples with 'make all' : Enabled -- Build timing scripts with 'make all': Disabled -- Build shared GTSAM libraries : Enabled -- Put build type in library name : Enabled -- Build libgtsam_unstable : Enabled -- Build for native architecture : Enabled -- Build type : Release -- C compilation flags : -O3 -DNDEBUG -- C++ compilation flags : -Wno-misleading-indentation -O3 -DNDEBUG -- GTSAM_COMPILE_FEATURES_PUBLIC : cxx_std_11 -- GTSAM_COMPILE_OPTIONS_PRIVATE : -Wall;-fPIC;$<$:-g;-fno-inline>;$<$:-O3>;$<$:-g;-O3>;$<$:-O3>;$<$:-g;-O3>;-Wno-unused-local-typedefs -- GTSAM_COMPILE_OPTIONS_PUBLIC : -march=native -- GTSAM_COMPILE_DEFINITIONS_PRIVATE : $<$:_DEBUG;EIGEN_INITIALIZE_MATRICES_BY_NAN>;$<$:NDEBUG>;$<$:NDEBUG;ENABLE_TIMING>;$<$:NDEBUG>;$<$:NDEBUG> -- GTSAM_COMPILE_DEFINITIONS_PUBLIC : -- GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG : -g;-fno-inline -- GTSAM_COMPILE_OPTIONS_PUBLIC_DEBUG : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_DEBUG : _DEBUG;EIGEN_INITIALIZE_MATRICES_BY_NAN -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_DEBUG : -- GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE : -O3 -- GTSAM_COMPILE_OPTIONS_PUBLIC_RELEASE : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELEASE : NDEBUG -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_RELEASE : -- GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING : -g;-O3 -- GTSAM_COMPILE_OPTIONS_PUBLIC_TIMING : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_TIMING : NDEBUG;ENABLE_TIMING -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_TIMING : -- GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING : -O3 -- GTSAM_COMPILE_OPTIONS_PUBLIC_PROFILING : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_PROFILING : NDEBUG -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_PROFILING : -- GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO : -g;-O3 -- GTSAM_COMPILE_OPTIONS_PUBLIC_RELWITHDEBINFO : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELWITHDEBINFO : NDEBUG -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_RELWITHDEBINFO : -- GTSAM_COMPILE_OPTIONS_PRIVATE_MINSIZEREL : -- GTSAM_COMPILE_OPTIONS_PUBLIC_MINSIZEREL : -- GTSAM_COMPILE_DEFINITIONS_PRIVATE_MINSIZEREL : -- GTSAM_COMPILE_DEFINITIONS_PUBLIC_MINSIZEREL : -- Use System Eigen : OFF (Using version: 3.3.7) -- Use Intel TBB : Yes -- Eigen will use MKL : MKL not found -- Eigen will use MKL and OpenMP : OpenMP found but GTSAM_WITH_EIGEN_MKL is disabled -- Default allocator : TBB -- Cheirality exceptions enabled : YES -- Build with ccache : No -- Packaging flags
-- CPack Source Generator : TGZ -- CPack Generator : TGZ -- GTSAM flags
-- Quaternions as default Rot3 : Disabled -- Runtime consistency checking : Disabled -- Rot3 retract is full ExpMap : Disabled -- Pose3 retract is full ExpMap : Disabled -- Deprecated in GTSAM 4 allowed : Enabled -- Point3 is typedef to Vector3 : Disabled -- Metis-based Nested Dissection : Enabled -- Use tangent-space preintegration: Enabled -- Build Wrap : Enabled -- MATLAB toolbox flags
-- Install matlab toolbox : Disabled -- Cython toolbox flags
-- Install Cython toolbox : Disabled -- =============================================================== -- Configuring done -- Generating done -- Build files have been written to: /home/lin/local/gtsam/build

build project

project structure

test_gtsam ├── build ├── CMakeLists.txt └── OdometryExample.cpp

CMakeLists.xtx

project(test_gtsam)
cmake_minimum_required(VERSION 2.8)

set(GTSAM_DIR /home/lin/local/lib/cmake/GTSAM)
find_package(GTSAM)
if(GTSAM_FOUND)  
  message(STATUS "Found GTSAM ${GTSAM_VERSION}")
else()
  message(STATUS "GTSAM Not Found")
endif()

include_directories(${GTSAM_INCLUDE_DIR})

add_executable(OdometryExample OdometryExample.cpp)
target_link_libraries(OdometryExample gtsam)

build project

$ cd /home/lin/develop/dev/test_gtsam/build
$ cmake ..
$ make
$ ./OdometryExample

issue

./OdometryExample: error while loading shared libraries: libmetis-gtsam.so: cannot open shared object file: No such file or directory

ProfFan commented 4 years ago

Before this is dealt with you can always use LD_LIBRARY_PATH to get going.

linzha0 commented 4 years ago

Hi @ProfFan , could you be more specific?

acxz commented 4 years ago

@CrazyPopLin followed your steps command by command (except replacing lin with acxz) and I could not reproduce the issue. It seems there is something else amiss.

Can you give us the output of ls ~/local/lib?

As well as the contents of ~/local/gtsam/build/install_manifest.txt

It would be much appreciated if you can post your file as a gist or as a dropdown element in the issue comment.

linzha0 commented 4 years ago

ls ~/local/lib

cmake libgtsam.so.4 libgtsam_unstable.so.4 libCppUnitLite.a libgtsam.so.4.0.2 libgtsam_unstable.so.4.0.2 libgtsam.so libgtsam_unstable.so libmetis-gtsam.so

install_manifest.txt

please check here.

Thanks.

linzha0 commented 4 years ago

I used the same build steps to install gtsam and build project in Jetson TX2 with jetpack 4.4.2(Ubuntu 18.04), got same error; Then use same steps to install gtsam and build project in Ubuntu 16.04, it's working. Just let you know.

ProfFan commented 4 years ago

@CrazyPopLin I mean you can add LD_LIBRARY_PATH that points to where libmetis-gtsam.so is in and see if that fixes your issue.

Ref: https://stackoverflow.com/questions/13428910/how-to-set-the-environmental-variable-ld-library-path-in-linux

acxz commented 4 years ago

@CrazyPopLin so it seems like that libmetis-gtsam.so is installed, but your executable cannot find it.

Glad to hear it's working on Ubuntu 16, but still very weird that it is not working for you on 18 or 20.

Can you change your CMakeLists.txt as follows and post the output, noting the new get_target_property() commands.

project(test_gtsam)
cmake_minimum_required(VERSION 2.8)

set(GTSAM_DIR /home/acxz/local/lib/cmake/GTSAM)
find_package(GTSAM)
if(GTSAM_FOUND)
  message(STATUS "Found GTSAM ${GTSAM_VERSION}")
else()
  message(STATUS "GTSAM Not Found")
endif()

include_directories(${GTSAM_INCLUDE_DIR})

add_executable(OdometryExample OdometryExample.cpp)
get_target_property(gtsam_link_lib gtsam INTERFACE_LINK_LIBRARIES)
message("${gtsam_link_lib}")
target_link_libraries(OdometryExample gtsam)

I get the following output:

-- GTSAM include directory:  /home/acxz/local/lib/cmake/GTSAM/../../../include
-- Found GTSAM 4.0.2
Boost::serialization;Boost::system;Boost::filesystem;Boost::thread;Boost::date_time;Boost::regex;Boost::timer;Boost::chrono;tbb;tbbmalloc;metis-gtsam
-- Configuring done
-- Generating done
-- Build files have been written to: /home/acxz/test-gtsam/build
linzha0 commented 4 years ago

@ProfFan ,thanks. @acxz , the entire output:

-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.43") found components: serialization system filesystem thread program_options date_time timer chrono regex 
-- GTSAM include directory:  /home/lin/local/lib/cmake/GTSAM/../../../include
-- Found GTSAM 4.0.2
Boost::serialization;Boost::system;Boost::filesystem;Boost::thread;Boost::date_time;Boost::regex;Boost::timer;Boost::chrono;tbb;tbbmalloc;metis-gtsam
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lin/develop/dev/test_gtsam/build
linzha0 commented 4 years ago

@acxz , this issue is solved by addling following in ~/.bashrc suggested by @ProfFan export LD_LIBRARY_PATH=/home/lin/local/lib/:$LD_LIBRARY_PATH.

But this issue is wired, so please let me know if you want to debug more. thanks for your suggestion.

dellaert commented 4 years ago

Thanks ! Will close for now

acxz commented 4 years ago

I am puzzled but out of ideas. Nevetheless, glad to hear you got it working, and I hope you enjoy using GTSAM!

cynosure4sure commented 4 years ago

Same issue when upgrading ROS Melodic code from 4.0.2 to 4.0.3 on Ubuntu 18.04. ROS code compiled correctly however at runtime gave error: error while loading shared libraries: libmetis-gtsam.so: cannot open shared object file: No such file or directory

Adding export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH to ~/.bashrc resolved the issue as mentioned above.

Thank you for the solution.

bloom256 commented 3 years ago

Perhaps ldconfig should be called after installing gtsam. See https://www.debian.org/doc/debian-policy/ch-sharedlibs.html#s-ldconfig

cynosure4sure commented 3 years ago

Perhaps ldconfig should be called after installing gtsam. See https://www.debian.org/doc/debian-policy/ch-sharedlibs.html#s-ldconfig

Thank you this fixed the problem.

berndpfrommer commented 3 years ago

This is a packaging bug.

jingyibo123 commented 3 years ago

ldconfig should not be necessary, and LD_LIBRARY_PATH is a no no for portability

There's clearly a lot missing in the generated GTSAMConfig.cmake and GTSAM-exports.cmake

When installed to a custom path( which is usually the PREFERED way to build and link against a thirdparty project from source), the libgtsam.so is unable to find libmetis-gtsam.so (as seen by ldd libgtsam.so), and import GTSAM with find_package(GTSAM) is quite painful.

AFAIK, either the old fashioned way, define GTSAM_LIBRARIES and GTSAM_LIBRARY_DIR, or the modern way, define cmake targets with correct dependencies...

Correct me if I'm wrong I'm no cmake expert...

berndpfrommer commented 3 years ago

When I try to fix this by creating a libgtsam4.triggers file in the debian directory:

activate-noawait ldconfig

I get the following cryptic lintian error when packaging: E: libgtsam4: repeated-trigger-name activate-noawait ldconfig (line 3) vs activate-noawait ldconfig (line 1) A web search didn't provide much clarity, but the answer to this stack exchange post mentions that the debian build tools add the trigger automatically, which may result in the above error message.

For now I will not include the ldconfig trigger also because it is not clear if it is still needed with the new package that uses the system-provided libmetis.

jlblancoc commented 3 years ago

For the records:

So good to see progress on #292 !

ProfFan commented 2 years ago

This is because you have multiple versions of GTSAM installed in different locations. Please search and remove them.

brunoeducsantos commented 2 years ago

Thanks a lot ! Indeed that was the problem.

Janphr commented 2 years ago

Under 20.04 and GTSAM 4.2.0 following solved it for me: sudo cp /usr/local/lib/libmetis-gtsam.so /usr/lib

sfod commented 1 year ago

I see that even the issue is closed, users encounter it from time to time. I believe, a proper way to fix it in linux environment is to set RPATH. It can be done using CMAKE_INSTALL_RPATH option. Something like the following:

cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_RPATH='\$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib'

Then, the installed library will have the RUNPATH property (I set CMAKE_INSTALL_PREFIX to /tmp/install):

$ readelf -a /tmp/install/lib/libgtsam.so | fgrep -i runpath     
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/tmp/install/lib]

$ ldd /tmp/install/lib/libgtsam.so | fgrep metis
    libmetis-gtsam.so => /tmp/install/lib/libmetis-gtsam.so (0x00007fc3b5f0a000)

If this doesn't work, sometimes CMAKE_SKIP_BUILD_RPATH=OFF and CMAKE_INSTALL_RPATH_USE_LINK_PATH=ON options are also required.

Maybe it should be added by gtsam library, but I' not sure about this.

wienans commented 1 year ago

This works: sudo cp /usr/local/lib/libmetis-gtsam.so /usr/lib But is not so nice and not the intended way, for me also calling ldconfig worked fine on ubuntu 20.04