Message: Re: How to link with home made .so files Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: How to link with home made .so files 

Forum: Installation and Configuration
Re: Question How to link with home made .so files (Alain Ferragut)
Date: 13 Apr, 2015
From: Ben Morgan <Ben Morgan>

On Thu, 02 Apr 2015 19:29:48 GMT, Alain Ferragut wrote:
> Hello, I have finally succeeded in compiling my own set of classes that
> I want to use with my G4 application. I have configured a cmake config
> file to obtain a directory where I have installed: --> Header files of
> my own programs in an include subdirectory, --> Shared objects files
> (.so)of my programs in a lib subdirectory.
> Now, I want to use my classes inside a G4 application. I know how to
> include the header files so that the compilation of the app can find
> them. But I don't know how to specify the path to the lib or something
> is missing because the link fails by saying : "no rule to build xxx".
> Suppose that I have a file called in my own lib
> subdirectory. How can I configure cmake in order that the linker will
> work to build the executable.
> Thanks,
> Alain

Let's say your library headers/so are installed in /foo/include and /foo/lib/ To tell CMake to use/link to the library, you can do:

# Your CMake script
set(MYANALYSE_INCLUDE_DIRS "/foo/include")
set(MYANALYSE_LIBRARY      "/foo/lib/")

target_link_libraries(myapplication "${MYANALYSE_LIBRARY}")

That of course hardcodes the paths to the headers/lib, but shows the basic idea, which is that CMake uses full paths to libraries for linking.

To avoid hardcoding the paths, you can supply a MyAnalyseConfig.cmake file installed alongside your library which CMake can use to configure everything for you. If your library is built with CMake, then it's very easy to create this, see here:

That does require CMake 2.8.8, so if you can only use an earlier version, an older method for generating the file is documented here:

To use this to find/link to your package, the CMake script would change to:

# CMake script
find_package(MyAnalyse REQUIRED)

target_link_libraries(myapplication "${MYANALYSE_LIBRARY}")

To get your project's CMake to find MyAnalayse, assume again that it's installed under /foo with the MyAnalyseConfig.cmake file(s) installed as in the documentation above. You just do:

$ cmake -DCMAKE_PREFIX_PATH=/foo 

The CMAKE_PREFIX_PATH variable is a PATH-style variable for pointing CMake to installed packages (see

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: How to link with home made .so files   (Alain Ferragut - 13 Apr, 2015)
(_ Ok: Re: How to link with home made .so files   (Alain Ferragut - 13 Apr, 2015)
(_ None: Re: How to link with home made .so files   (Ben Morgan - 14 Apr, 2015)
 Add Message Add Message
to: "Re: How to link with home made .so files"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]