I'm learning CMake at the moment and I'm stuck with a problem. I have a library(that I have created previously with CMake) named 'libLibraryName'(I know, not the best name). This library contains just one function that prints a message and was formed by combining two files(1 header file wtih the prototype of the function and one .cpp with it's implementation).
Now I put the function in a folder and I'm trying to make a .cpp file make use of this library. This is the structure of my folder(as you can see the library is in the .../Library folder).
.
├── build
├── CMakeLists.txt
├── include
│ └── header.h
├── Library
│ └── libLibraryName.so
├── main.cpp
└── src
└── header.cpp
I wrote this CMakeLists:
cmake_minimum_required(VERSION 3.5.1)
# Project name
project(Project_Name)
# Include the existing library's name and then link it's path
# Make sure to provide a valid library name
set( PROJECT_LINK_LIBS libLibraryName.so )
link_directories(/home/uidr0938/CMake_Exercises/Library)
# Add path of the header files
include_directories(include)
# Create an executable with your main application's code
add_executable(Application main.cpp)
# And link the library to that application
target_link_libraries(Application ${PROJECT_LINK_LIBS})
Then I went into build and ran 'cmake ..'. This worked. But then when I wrote 'make' I get this following error:
/usr/bin/ld: cannot find -lLibraryName
collect2: error: ld returned 1 exit status
CMakeFiles/Application.dir/build.make:94: recipe for target 'Application' failed
make[2]: *** [Application] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Application.dir/all' failed
make[1]: *** [CMakeFiles/Application.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
It is if the program is looking for the library at a different path not the one I provide it with the link_directories command.
Please help me solve this so I can use that library with my main function. Thank you.
I used a virtual linux machine for this example.