Quantcast

Install an executable with his libraries

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Install an executable with his libraries

Anthony Todisco
Hello,

I'm new with CMake and for a project I try to build and install a program. I've done some research on the forum and try what have found but nothing seems to work :/.

Here is my configuration and my CMakeList

Application/
     |___ Bin
     |___ Includes
              |___ BaseLib
                     |___ BaseObject.h
              |___ ComposeLib
                     |___ ComposeObject.h
              |___ Manager
                     |___ manager.h
     |___ Src
              |___ BaseLib
                     |___ BaseObject.cpp
                     |___ CMakeList.txt (2)
              |___ ComposeLib
                     |___ ComposeObject.cpp
                     |___ CMakeList.txt (3)
              |___ Manager
                     |___ Manager.cpp
                     |___ CMakeList.txt (4)
     |___ CMakeList.txt (1)

The CMakeList in the root is

# Set the cmake version
cmake_minimum_required(VERSION 2.6)
 
set(BUILD_SHARED_LIBS ON)
set(BUILD_PATH "Bin/${CMAKE_BUILD_TYPE}/")
MESSAGE( "General build path ${BUILD_PATH}" )
 
# Set the list of directory which contain the other CMakeList
add_subdirectory(Src/BaseLib)
add_subdirectory(Src/ComposeLib)
add_subdirectory(Src/Manager)


The CMakeList for BaseLib is

# Set the cmake version
cmake_minimum_required(VERSION 2.6)
 
# Set the project name
project(BaseLib)
 
# Configure project
set(BUILD_SHARED_LIBS ON)
set(BUILD_PATH "${CMAKE_BUILD_TYPE}/")
 
#Display Build path
set(LIBRARY_OUTPUT_PATH ../../Bin/${BUILD_PATH})
 
#Include .h files directory
include_directories(../../Includes/BaseLib)
 
#Define librarie
add_library(
        BaseLib
        SHARED
       ../../Includes/BaseLib/BaseObject.h
      BaseObject.cpp
)
 
set_target_properties(BaseLib PROPERTIES PREFIX "")
install(TARGETS BaseLib
      RUNTIME DESTINATION bin COMPONENT libraries
     LIBRARY DESTINATION lib COMPONENT libraries
     ARCHIVE DESTINATION lib/static COMPONENT libraries)

The CMakeList for ComposeLib is

# Set the cmake version
cmake_minimum_required(VERSION 2.6)
 
# Set the project name
project(ComposeLib )
 
# Configure project
set(BUILD_SHARED_LIBS ON)
set(BUILD_PATH "${CMAKE_BUILD_TYPE}/")
 
#Display Build path
set(LIBRARY_OUTPUT_PATH ../../Bin/${BUILD_PATH})
 
#Include .h files directory
include_directories(../../Includes/BaseLib ../../Includes/ComposeLib)
link_directories(../../Bin/${BUILD_PATH})
 
#Define librarie
add_library(
        ComposeLib
        SHARED
       ../../Includes/ComposeLib/ComposeObject.h
      ComposeObject.cpp
)

target_link_libraries(
        ComposeLib
        BaseLib
)
 
set_target_properties(ComposeLib PROPERTIES PREFIX "")
install(TARGETS ComposeLib
      RUNTIME DESTINATION bin COMPONENT libraries
     LIBRARY DESTINATION lib COMPONENT libraries
     ARCHIVE DESTINATION lib/static COMPONENT libraries)

And finally the CMakeList for the Manager


# Set the cmake version
cmake_minimum_required(VERSION 2.6)
 
# Set the project name
project(Manager)
 
# Configure project
set(BUILD_SHARED_LIBS ON)
set(BUILD_PATH "${CMAKE_BUILD_TYPE}/")
set(EXECUTABLE_OUTPUT_PATH ../../Bin/${BUILD_PATH})
 
#Include .h files directory
include_directories(../../Includes/BaseLib
../../Includes/ComposeLib
../../Includes/Manager)
 
#Define link libraries folder
link_directories(../../Bin/${BUILD_PATH})
 
add_executable(
        Manager
        ../../Includes/Manager/Manager.h
        Manager.cpp
)
 
target_link_libraries(
        Manager
        BaseLib
        ComposeLib
        pthread
)
 
set_target_properties(Manager PROPERTIES PREFIX "")
install(TARGETS Manager
                RUNTIME DESTINATION bin COMPONENT libraries
                 LIBRARY DESTINATION lib COMPONENT libraries
                 ARCHIVE DESTINATION lib/static COMPONENT libraries)

The build works fine and if I launch manager on the bin directory from the build tree, there is no problem. However, when I use make install, all the files are correctly installed /usr/local/lib and /usr/local/bin but I can't launch Manager exectuable. A message informs me that the executable can't find BaseLib.so.

I don't know where my error is :/.
Thank you for all the help you can provide me.

ps: sorry for my english, I'm French.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Install an executable with his libraries

Rolf Eike Beer
> Hello,
>
> I'm new with CMake and for a project I try to build and install a program.
> I've done some research on the forum and try what have found but nothing
> seems to work :/.

[...]

> The build works fine and if I launch manager on the bin directory from the
> build tree, there is no problem. However, when I use make install, all the
> files are correctly installed /usr/local/lib and /usr/local/bin but I
> can't
> launch Manager exectuable. A message informs me that the executable can't
> find BaseLib.so.
>
> I don't know where my error is :/.

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

Eike
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Install an executable with his libraries

Anthony Todisco
Thank you very much, it works fine now :D.

I've missed this step :/

2012/1/18 Rolf Eike Beer <[hidden email]>
> Hello,
>
> I'm new with CMake and for a project I try to build and install a program.
> I've done some research on the forum and try what have found but nothing
> seems to work :/.

[...]

> The build works fine and if I launch manager on the bin directory from the
> build tree, there is no problem. However, when I use make install, all the
> files are correctly installed /usr/local/lib and /usr/local/bin but I
> can't
> launch Manager exectuable. A message informs me that the executable can't
> find BaseLib.so.
>
> I don't know where my error is :/.

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

Eike
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Install an executable with his libraries

Eric Noulard
2012/1/18 Anthony Todisco <[hidden email]>:
> Thank you very much, it works fine now :D.
>
> I've missed this step :/

On Unix you can configure RPATH in order to avoid the LD_LIBRARY_PATH update
and/or tolerate more easily multiple version of the same lib for
different executable.

Have a look at:
http://www.cmake.org/Wiki/CMake_RPATH_handling


--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Install an executable with his libraries

Anthony Todisco
Thank you Eric for this link, but I don't really understand how to use RPATH with CMake.

Could you provide me piece of advice for my case?


2012/1/18 Eric Noulard <[hidden email]>
2012/1/18 Anthony Todisco <[hidden email]>:
> Thank you very much, it works fine now :D.
>
> I've missed this step :/

On Unix you can configure RPATH in order to avoid the LD_LIBRARY_PATH update
and/or tolerate more easily multiple version of the same lib for
different executable.

Have a look at:
http://www.cmake.org/Wiki/CMake_RPATH_handling


--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Install an executable with his libraries

Eric Noulard
2012/1/19 Anthony Todisco <[hidden email]>:
> Thank you Eric for this link, but I don't really understand how to use RPATH
> with CMake.

The RPATH usage control with CMake is done using
4 variables:

CMAKE_SKIP_BUILD_RPATH
CMAKE_BUILD_WITH_INSTALL_RPATH
CMAKE_INSTALL_RPATH
CMAKE_INSTALL_RPATH_USE_LINK_PATH

you can get the document of each of those vars with

cmake --help-variable <VarName>

> Could you provide me piece of advice for my case?

RPATH is a Unix way to put inside a binary executable
an explicit link to the libraries on which this executable depends.

In your case the "Manager" executable depends on
the "BaseLib, ComposeLib and phtread" as stated by
your
target_link_libraries(
       Manager
       BaseLib
       ComposeLib
       pthread
)

when you run "Manager" the system thus need to load
the BaseLib, ComposeLib and phtread libs.

phtread is [probably] found automatically because it is installed
system-wide and I won't explain that.

BaseLib and ComposeLib are built in your project.

CMake knows all of this, then:

in the build tree it uses RPATH in order to make
Manager run easily without fiddling with LD_LIBRARY_PATH.

At the install location (/usr/local/... in your case)
CMake does not setup RPATH inside the **installed** executable
unless you tell him to do so, by specifying the install rpath:
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

from "http://www.cmake.org/Wiki/CMake_RPATH_handling"
you can read
"when installing all executables and shared libraries will be
relinked, so they will find all libraries they need"

by the way you should NOT do that:

#Define link libraries folder
link_directories(../../Bin/${BUILD_PATH})

this should not be necessary, see:

cmake --help-command link_directories
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Loading...