[Dune] Link to external shared library

Markus Blatt markus at dr-blatt.de
Wed May 17 20:24:52 CEST 2017


Hi,

On Wed, May 17, 2017 at 02:22:05PM +0000, Tobias Kasper Skovborg Ritschel wrote:
> My question in short:
> Do I need to use DUNE buildsystem functionality (e.g. dune_add_library) to link with an external shared library, or can I use CMake functionality?
> 

No there should be no need for this.

> The longer explanation:
> I am working on a DUNE module (ResSim), 

Sounds like a reservoir simulator. 

> and I would like to use functions from a shared library (libThermoLib.so) in that code. I have tried to use CMake commands in the following way
> 
> -------------------------------------------------------------------------------------------------------------------------------------------
> 
> # Find the ThermoLib library
> find_library(thermolib_LIBRARY ThermoLib)
> message(STATUS "setting thermolib_LIBRARY="${thermolib_LIBRARY}"")
> 
> # Find the ThermoLib include directory
> find_path(thermolib_INCLUDE_DIRS ThermoLib.h)
> message(STATUS "setting thermolib_INCLUDE_DIRS="${thermolib_INCLUDE_DIRS}"")
> 
> # Add library
> add_library(thermolib SHARED IMPORTED GLOBAL)
> set_target_properties(thermolib PROPERTIES
> IMPORTED_LOCATION "${thermolib_LIBRARY}"
> INTERFACE_INCLUDE_DIRECTORIES "${thermolib_INCLUDE_DIRS}")

 I have never used the above. What does it buy you? 
You could skip it and use target_link_libraries("ResSim" ${thermolib_LIBRARY})
below with apropriate include_directories(${thermolib_INCLUDE_DIRS]), couldn't you?
> 
> # Add executable
> add_executable("ResSim" main.cc)
> 
> # Link libraries
> target_link_dune_default_libraries("ResSim")
> target_link_libraries("ResSim" thermolib)
> 

> 
> The -DCMAKE_PREFIX_PATH ensures that find_library and find_path finds libThermoLib.so and its include directory (and I have checked that they do). However, I get a linker error:
> 
> CMakeFiles/ResSim.dir/main.cc.o: In function `main':
> main.cc:(.text.startup+0x87): undefined reference to `LoadParams(int*, int, int, double*, double*)'
> collect2: error: ld returned 1 exit status
> 

Maybe the linker line gives some insight? With make it shown when
using "make VERBOS=1"

Markus

-- 
Dr. Markus Blatt - HPC-Simulation-Software & Services http://www.dr-blatt.de
Hans-Bunte-Str. 8-10, 69123 Heidelberg, Germany
Tel.: +49 (0) 160 97590858




More information about the Dune mailing list