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 static lib error "No rule to make target"

I want to use a CMakeLists.txt file to create my library. I want to include other libraries used by my functions, but I receive the following error:

make[2]: *** No rule to make target '/libs/libgsl.a', needed by 'mylib'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/mylib.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

My CMakeLists.txt looks like the following:

cmake_minimum_required(VERSION 2.8)

project(mylib)

# find header & source
file(GLOB_RECURSE SOURCE_C "src/*.c")
file(GLOB_RECURSE SOURCE_CPP "src/*.cpp")
file(GLOB_RECURSE HEADER "include/*.h")

add_executable(mylib
  ${SOURCE_C}
  ${SOURCE_CPP}
  ${HEADER}
)

# includes
include_directories( /include )
link_directories( /libs )

source_group("Header include" FILES ${HEADER})
source_group("Source src"     FILES ${SOURCE_C})
source_group("Source src"     FILES ${SOURCE_CPP})

# opencv package
find_package( OpenCV REQUIRED)
target_link_libraries(mylib PUBLIC opencv_highgui)

# link libraries
target_link_libraries(${PROJECT_NAME} PUBLIC m)
target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libgsl.a)
target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libz.a)
target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libpng16.a)

My folder structure (of dir mylib looks like the following:

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

mylib--build
        |
       CMakeLists.txt
        |
       include--my .h files, for static lib headers I have separate folders (e.g. include/gsl/gsl_sort.h)
        |      
       libs--my static libs e.g. libgsl.a
        |
       src--my c and cpp files calling functions from the static libs

I include e.g. the gsl-library to my .cpp file like this:

#include "../include/gsl/gsl_sort.h"

>Solution :

target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libgsl.a)
target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libz.a)
target_link_libraries(${PROJECT_NAME} PUBLIC /libs/libpng16.a)

Should be:

target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/libs/libgsl.a)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/libs/libz.a)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/libs/libpng16.a)

The way you have it, the libraries should exist in the folder /libs/ instead of a sub-directory of your current directory.

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