Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CMake Linking library with full path and with target_include_directories

I came to a problem that I do not understand why this works in such a ways.
I am linking static libraries, specially libgmp-10 and libmpfr-4. These are static libraries from CGAL.

This does not work:

list(APPEND petras_include_paths 
  #cgal
  "${CMAKE_BINARY_DIR}/install/cgal/include"
  "${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/include"
  "${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib"
  #"C:/msys64/mingw64/lib/" #GCC
  )

 target_include_directories(${PROJECT_NAME} PRIVATE "$<BUILD_INTERFACE:${petras_include_paths}>") #header for the library

target_link_libraries(${PROJECT_NAME} PRIVATE 
  libgmp-10
  libmpfr-4
  )

This works:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

target_link_libraries(${PROJECT_NAME} PRIVATE 
  "${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib/libgmp-10.lib" 
  "${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib/libmpfr-4.lib"
  ) 

Why?
I thought that target_include_directories add the path to libraries, so that in target_link_libraries I should only need to specify the name of the library, not the full path.

>Solution :

target_include_directories adds #include directories, not library search paths. target_link_directories adds link directories.

Before proceeding, you might want to read https://doc.cgal.org/latest/Manual/devman_create_and_use_a_cmakelist.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading