Using external libraries with deal.II

95 views
Skip to first unread message

Animesh Rastogi IIT Gandhinagar

unread,
Dec 17, 2020, 2:19:48 PM12/17/20
to deal.II User Group
Dear deal.II community

I would like to use some external libraries such as Eigen and Spectra in dealii for one of my projects. These are both header-only C++ libraries. Could someone please tell me about how to integrate these libraries (installed in my system) with dealii? What changes do I need to make in the deal.II cmake build system before recompiling and reinstalling it..

Thanks!

Animesh

Daniel Arndt

unread,
Dec 17, 2020, 2:54:18 PM12/17/20
to dea...@googlegroups.com
Animesh,

Assuming that the packages export CMake configurations you can just do a standard

find_package(Spectra REQUIRED)
target_link_libraries(my_project Spectra::Spectra)

in the CMakeLists.txt for your project.

Best,
Daniel

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/4c387a54-4f16-48cc-80c9-9bc1479ee038n%40googlegroups.com.

Wolfgang Bangerth

unread,
Dec 17, 2020, 3:03:47 PM12/17/20
to dea...@googlegroups.com
On 12/17/20 12:54 PM, Daniel Arndt wrote:
>
> in the CMakeLists.txt for your project.

In other words, you don't need to do anything about deal.II itself at all
unless you plan on modifying deal.II to use these external libraries.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Animesh Rastogi IIT Gandhinagar

unread,
Dec 21, 2020, 9:04:50 AM12/21/20
to deal.II User Group
Dear Daniel and Prof. Bangerth,

I did exactly as you suggested. My package export cmake configurations. I am getting the following error and cant figure out the reason. It is not able to link the executable with the package.

CMake Error at CMakeLists.txt:42 (TARGET_LINK_LIBRARIES):
  Cannot specify link libraries for target
  "Quasi_Static_Finite_Strain_Beam_Buckling_Analysis" which is not built by
  this project.


-- Configuring incomplete, errors occurred!
See also "/home/animesh/Documents/dealii/dealii-9.2.0/examples/Quasi_Static_Finite_Strain_Beam_Buckling_Analysis/CMakeFiles/CMakeOutput.log".

I am attaching the cmakelists.txt for your reference.

Thanks!
Animesh
CMakeLists.txt

Animesh Rastogi IIT Gandhinagar

unread,
Dec 21, 2020, 10:00:40 AM12/21/20
to deal.II User Group
What I understood after struggling through the issue is that my cmakelists.txt is in autopilot style. In the autopilot style, it doesn't build the executable right away after doing "cmake .". It builds the executable after I run "make" command (as per my observation). I think this is why it is saying that "Cannot specify link libraries for target  "Quasi_Static_Finite_Strain_Beam_Buckling_Analysis" which is not built by this project." If I am correct here, what would be a way to fix the issue?

Thanks!

Animesh

Wolfgang Bangerth

unread,
Dec 21, 2020, 12:31:51 PM12/21/20
to dea...@googlegroups.com

Animesh,

> I did exactly as you suggested. My package export cmake configurations. I am
> getting the following error and cant figure out the reason. It is not able to
> link the executable with the package.
>
> CMake Error at CMakeLists.txt:42 (TARGET_LINK_LIBRARIES):
>   Cannot specify link libraries for target
>   "Quasi_Static_Finite_Strain_Beam_Buckling_Analysis" which is not built by
>   this project.
>
>
> -- Configuring incomplete, errors occurred!
> See also
> "/home/animesh/Documents/dealii/dealii-9.2.0/examples/Quasi_Static_Finite_Strain_Beam_Buckling_Analysis/CMakeFiles/CMakeOutput.log".

At the place where you call TARGET_LINK_LIBRARIES, you have not declared any
targets at all. So the error message seems correct to me.

You may want to move this line below DEAL_II_INVOKE_AUTOPILOT which declares
the target for you. Here's an example from the code gallery that does
something similar:

https://github.com/dealii/code-gallery/blob/master/parallel_in_time/CMakeLists.txt

Matthias Maier

unread,
Dec 21, 2020, 3:11:08 PM12/21/20
to dea...@googlegroups.com
Hi,

No, the problem is much simpler. You have to reorganize your
CMakeLists.txt so that you search for your libraries and add them to
your link interface after the PROJECT() call and after the
DEAL_II_INVOKE_AUTOPILOT CALL(). It is simplest to put everything last:


# The default CMakeLists.txt file does the following:

FIND_PACKAGE(deal.II 9.1 QUIET [...]) # finds deal.II configuration

DEAL_II_INITIALIZE_CACHED_VARIABLES() # sets compiler and other cached variables
PROJECT(${TARGET}) # initializes compiler toolchain

DEAL_II_INVOKE_AUTOPILOT() # defines executable target with the name stored in
# variable "${TARGET}"


# NOW, you can search for your external libraries:

FIND_PACKAGE(Eigen3 REQUIRED)
FIND_PACKAGE(Spectra REQUIRED)

# and NOW you can add them to the target. (Simply use the variable
# ${TARGET} where you already stored the name of the project):

TARGET_LINK_LIBRARIES(${TARGET} Spectra::Spectra)



Best,
Matthias

Animesh Rastogi IIT Gandhinagar

unread,
Dec 23, 2020, 3:48:00 AM12/23/20
to deal.II User Group
Dear Prof. Maier and Prof. Bangerth,

Thank you for your help. I was able to fix the issue with your suggestions.

Animesh
Reply all
Reply to author
Forward
0 new messages