Message: Re: How to use external library(.so or .a) Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Note Re: How to use external library(.so or .a) 

Forum: Installation and Configuration
Re: Question How to use external library(.so or .a) (Huagang Yan)
Date: 29 Nov, 2016
From: Ben Morgan <Ben Morgan>

On Mon, 28 Nov 2016 03:06:49 GMT, Huagang Yan wrote:
> Then I used cmake to build the project in a build directory, and opened
> it in Eclipse. After clicking build, the following error information
> appeared:
> 
> undefined reference to 'xxxxx1' undefined reference to 'xxxxx2' ...
> 
> xxxxx's are methods defined in the header file associated with the
> library. In Eclipse, I added the library path and library, and set
> LD_LIBRARY_PATH = /usr/local/lib. But none of the efforts work. I was
> thinking of editing the Makefile directly. However, it is too
> complicated to modify without undesired consequence.
> 
> I have been working on this issue for days, really exhausted, and I
> think it shouldn't be a big problem, as the example applying the xxx
> library works just as expected.
> 
> Any help is highly appreciated.
> 

As with the GNUmake case, the library and header path need to be declared in the CMake scripts. This can be hardcoded for /usr/local/ as

# CMakeLists.txt for your project
... other commands ...

set(XXX_INCLUDE_DIRS "/usr/local/include")
set(XXX_LIBRARY "/usr/local/lib/libxxx.so") 

include_directories(${XXX_INCLUDE_DIRS})

add_executable(yourexe ...)
target_link_libraries(yourexe ${XXX_LIBRARY})

That should work, but note it hardcodes in the paths to the "XXX" library. If you need more flexibility than that, or your application is going to be used by multiple people, consider using CMake's facilities for finding headers/libraries etc, such as find_path, find_library and find_package. In the latter case, see also the documentation on writing modules for use with find_package.

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

1 Feedback: Re: How to use external library(.so or .a)   (Huagang Yan - 30 Nov, 2016)
 Add Message Add Message
to: "Re: How to use external library(.so or .a)"

 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 ]