Error "There is no rule for creating a target" in cmake when connecting to a shared library

On Ubuntu, I downloaded the third-party shared library mylibrary.so , which I placed in the /home/karnivaurus/Libraries directory. I also placed the associated header file myheader.h in the directory /home/karnivaurus/Headers . Now I want to link this library with my C ++ code using cmake. Here is my CMakeLists.txt file:

 cmake_minimum_required(VERSION 2.0.0) project(DemoProject) include_directories(/home/karnivaurus/Headers) add_executable(demo demo.cpp) target_link_libraries(demo /home/karnivaurus/Libraries/mylibrary) 

However, this gives me an error message:

 :-1: error: No rule to make target `/home/karnivaurus/Libraries/mylibrary', needed by `demo'. Stop. 

What's happening?

+6
source share
1 answer

You can use the full path to the static library. To bind w / dynamic, it is best to use link_directories() as follows:

 cmake_minimum_required(VERSION 2.0.0) project(DemoProject) include_directories(/home/karnivaurus/Headers) link_directories(/home/karnivaurus/Libraries) add_executable(demo demo.cpp) target_link_libraries(demo mylibrary) 

and make sure mylibrary has the lib prefix and the .so suffix in the file name (i.e. the full name /home/karnivaurus/Libraries/libmylibrary.so ).

To make the project more flexible, it’s better to write a finder module and avoid hard code paths like /home/karnivaurus/*

0
source

Source: https://habr.com/ru/post/1206445/


All Articles