0

When I am compiling a C++ program with cmake, I keep getting this error. The relevant cmake code is:

CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7)
FIND_PATH(OPENSCENEGRAPH_LIB_DIR libso.so osg.lib
            PATHS
            $ENV{OSG_ROOT}/lib
            /usr/local/lib
)
LINK_DIRECTORIES(${OPENSCENEGRAPH_LIB_DIR})

TARGET_LINK_LIBRARIES(${EXAMPLE_NAME}
    debug osg${CMAKE_DEBUG_POSTFIX} optimized osg
    debug osgUtil${CMAKE_DEBUG_POSTFIX} optimized osgUtil
    debug osgViewer${CMAKE_DEBUG_POSTFIX} optimized osgViewer
    debug osgDB${CMAKE_DEBUG_POSTFIX} optimized osgDB
    debug osgGA${CMAKE_DEBUG_POSTFIX} optimized osgGA
    debug OpenThreads${CMAKE_DEBUG_POSTFIX}
    optimized OpenThreads
)
INSTALL(TARGETS ${EXAMPLE_NAME} RUNTIME DESTINATION
        ${CMAKE_INSTALL_PREFIX}/bin)

But the file libosgViewer.so.202 is present in the directory /usr/local/lib. Then why is binary is giving the error libosgViewer.so.202: cannot open shared object file: No such file or directory.

The CPP Code is:

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
int main( int argc, char** argv )
{
osgViewer::Viewer viewer;
viewer.setSceneData( osgDB::readNodeFile("cessna.osg") );
return viewer.run();
}

I am fairly to new to both openscenegraph and cmake, so I am not sure how to solve this issue. I am on Ubuntu 20.0.4.

lokit khemka
  • 349
  • 3
  • 11
  • 1
    Was the error happened when you compile or run ? – long.kl Feb 11 '22 at 08:50
  • 1
    I think `/usr/local/lib` is not in the default search paths for the dynamic linker. Can you try to add it? `LD_LIBRARY_PATH=/usr/local/lib ./program`. – spectras Feb 11 '22 at 08:50
  • Error is runtime. When trying to execute the executable. – lokit khemka Feb 11 '22 at 08:53
  • 1
    "When trying to execute the executable." - Most likely, you are trying to execute the **installed** executable. Because the one which is *built* contains absolute RPATH for all linked libraries, so it shouldn't emit such errors. You may read this article about adjusting RPATH in CMake: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling – Tsyvarev Feb 11 '22 at 09:02

0 Answers0