Problem about modifying CMakeList.txt to add library

492 views
Skip to first unread message

Pai Liu

unread,
May 16, 2018, 2:54:39 AM5/16/18
to deal.II User Group
Hi all,

I am learning Step-8 in the tutorial. I want to use the library "Armadillo" (which is a library for scientific computing and linear algebra) together with dealii in step-8.cc.
To compile a cpp file that only depends on the Armadillo library, one needs to excute the following commends at the commend line : "g++ example.cpp -o example -O2 -larmadillo"
So I replace "mylib" in dealii documentation about modifying cmakelist.txt with "armadillo", and modify the CMakeList.txt file as the following

_____________________________________________________________________
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)

FIND_PACKAGE(deal.II 8.5.0 REQUIRED
  HINTS ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
  )
DEAL_II_INITIALIZE_CACHED_VARIABLES()

PROJECT(myproject)

ADD_LIBRARY(armadillo)
DEAL_II_SETUP_TARGET(armadillo)

ADD_EXECUTABLE(mycode step-8.cc)
DEAL_II_SETUP_TARGET(mycode)

TARGET_LINK_LIBRARIES(mycode armadillo)
_____________________________________________________________________

And I got the the following error:

-- Using the deal.II-8.5.1 installation found at /home/liu/deal.ii-candi/deal.II-v8.5.1
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_initialize_cached_variables.cmake
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_setup_target.cmake
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_query_git_information.cmake
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_pickup_tests.cmake
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_add_test.cmake
-- Include macro /home/liu/deal.ii-candi/deal.II-v8.5.1/share/deal.II/macros/macro_deal_ii_invoke_autopilot.cmake
You have called ADD_LIBRARY for library armadillo without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: Cannot determine link language for target "armadillo".
CMake Error: CMake can not determine linker language for target: armadillo
-- Generating done
-- Build files have been written to: /home/liu/P/homogenization





Can anyone help me about this issue about add library?
Many thanks in advance!
 

David Wells

unread,
May 16, 2018, 1:53:36 PM5/16/18
to deal.II User Group
Hi Pai,

I think that there is an easier way to do this. More exactly: armadillo should not be a target since we don't have to compile anything: we should just be able to specify the library we need to link against and (possibly) a path to the headers and be done.

Have you installed armadillo in a standard location? If so then you should be able to just append

TARGET_LINK_LIBRARIES(${TARGET} armadillo)

to the end of CMakeLists.txt (after the call to PROJECT and DEAL_II_INVOKE_AUTOPILOT)

and things should work correctly.

Thanks,
David Wells

P.S. the CMake module for setting up armadillo looks for a lot of things that don't exist on my computer; I recommend avoiding using FIND_PACKAGE.

Daniel Arndt

unread,
May 16, 2018, 5:47:11 PM5/16/18
to deal.II User Group
Pal,

We also just updated the CMakeLists.txt file for an example in our code-gallery that uses armadillo.

Best,
Daniel

Pai Liu

unread,
May 17, 2018, 1:21:32 AM5/17/18
to deal.II User Group
Dear Daniel Arndt,

Thank you for your reply! The link is very helpful! Now my CMakeList.txt works!

Best,
Pai 

Pai Liu

unread,
May 17, 2018, 1:30:34 AM5/17/18
to deal.II User Group
Dear David Wells,

Thank you for your reply! Your explanation helps me to understand this process better. Yestoday I tried to use "FIND_PACKAGE" as following and it works:

_________________________________________________________

FIND_PACKAGE(Armadillo)

INCLUDE_DIRECTORIES(${ARMADILLO_INCLUDE_DIRS})

ADD_EXECUTABLE(${TARGET} ${TARGET_SRC})
DEAL_II_SETUP_TARGET(${TARGET})

TARGET_LINK_LIBRARIES(${TARGET} ${ARMADILLO_LIBRARIES})

_________________________________________________________


I will try the commends you recommended later! Thank you very much!

Best,
Pai

Animesh Rastogi IIT Gandhinagar

unread,
Dec 23, 2020, 3:52:38 AM12/23/20
to deal.II User Group
Hi Daniel,

I also want to use armadillo for one of my projects. I did exactly as you suggested in the link above. The cmake worked perfectly. However, on doing make run, I am getting the following error. I installed armadillo using the apt-get package manager - command was - sudo apt-get install libarmadillo-dev

Error:

/usr/bin/ld.gold: error: /usr/include/armadillo:1:4: syntax error, unexpected STRING
/usr/bin/ld.gold: error: /usr/include/armadillo: not an object or archive
collect2: error: ld returned 1 exit status
CMakeFiles/Quasi_Static_Finite_Strain_Beam_Buckling_Analysis.dir/build.make:122: recipe for target 'Quasi_Static_Finite_Strain_Beam_Buckling_Analysis' failed
make[3]: *** [Quasi_Static_Finite_Strain_Beam_Buckling_Analysis] Error 1
CMakeFiles/Makefile2:163: recipe for target 'CMakeFiles/Quasi_Static_Finite_Strain_Beam_Buckling_Analysis.dir/all' failed
make[2]: *** [CMakeFiles/Quasi_Static_Finite_Strain_Beam_Buckling_Analysis.dir/all] Error 2
CMakeFiles/Makefile2:138: recipe for target 'CMakeFiles/run.dir/rule' failed
make[1]: *** [CMakeFiles/run.dir/rule] Error 2
Makefile:144: recipe for target 'run' failed
make: *** [run] Error 2

I was wondering if you can help me with this issue!

Thanks a lot!

Animesh

Animesh Rastogi IIT Gandhinagar

unread,
Dec 24, 2020, 6:16:05 AM12/24/20
to deal.II User Group
Hi Daniel,

I was able to sort this issue out. What I did was removed everything related to armadillo in the cmakelists.txt and just linked armadillo to my target using  the following line in the end of the file
TARGET_LINK_LIBRARIES(${TARGET} armadillo)
I am able to run small programs using armadillo within dealii.

I have another question which might not be in the scope of this forum. However, since you and Jean have worked with armadillo (by looking at the Ceres code gallery program), I was wondering if any of you can help.

My question is, I want to use the eigenvalue problem solving capability of armadillo in my code. However, my matrix type is of BlockSparseMatrix in dealii. How do I go about using my BlockSparseMatrix with the available armadillo functions that use sp_mat type matrices? One idea that I thought was to print my block_sparse_matrix using the function block_write() that prints the dealii Sparse_matrix in a binary format. However, I am not able to read that file using armadillo's functionality to load binary files.

Thanks!

Animesh

Wolfgang Bangerth

unread,
Dec 29, 2020, 12:28:44 PM12/29/20
to dea...@googlegroups.com

> My question is, I want to use the eigenvalue problem solving capability of
> armadillo in my code. However, my matrix type is of BlockSparseMatrix in
> dealii. How do I go about using my BlockSparseMatrix with the available
> armadillo functions that use sp_mat type matrices
> <https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Farma.sourceforge.net%2Fdocs.html%23SpMat&data=04%7C01%7CWolfgang.Bangerth%40colostate.edu%7C3c0f13141aa44d63d86808d8a7fd509e%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C637444053733683541%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=oAIyMJ24BSpj%2Ba%2FLVuLeQKBkCsjBL%2FYtzXXoeOBV00I%3D&reserved=0>?
> One idea that I thought was to print my block_sparse_matrix using the function
> block_write()
> <https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.dealii.org%2Fcurrent%2Fdoxygen%2Fdeal.II%2FclassSparseMatrix.html%23a8b32b99a054482f06fc026248c27bb74&data=04%7C01%7CWolfgang.Bangerth%40colostate.edu%7C3c0f13141aa44d63d86808d8a7fd509e%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C637444053733693536%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=xdRe1JdGjZP9Lqs6bvluJjwMLhXnoJjOSgyczMfjPOc%3D&reserved=0>
> that prints the dealii Sparse_matrix in a binary format. However, I am not
> able to read that file using armadillo's functionality to load binary files
> <https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Farma.sourceforge.net%2Fdocs.html%23save_load_mat&data=04%7C01%7CWolfgang.Bangerth%40colostate.edu%7C3c0f13141aa44d63d86808d8a7fd509e%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C637444053733693536%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Nbr5JZGjiCC7fx%2FMfGPvl6p0Ji39zLFeeW9Wv8aaAi8%3D&reserved=0>.

Just write a function that copies the data from one object to another. You can
iterate over deal.II matrix entries, and then you just need to figure out how
Armadillo wants its matrices filled.

Best
W.

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

Reply all
Reply to author
Forward
0 new messages