I'm new to cmake/make so I'm trying to do a simple compilation with include and lib directories as well as a library to link to the main file.
My directory structure looks like this
PROJECTDIRECTORY/
main.c
CMAKELISTS.txt
include/
add.h
lib/
add.a
build/
My main.c contains
#include <add.h>
int main(void)
{
add(5,10);
return 0;
}
My add.h contains
int add(int x,int y);
And my add.a is a static library which I compiled from add.c which contains the implementation.
Finally in my CMakeLists.txt I have
cmake_minimum_required (VERSION 3.6)
project(addproject)
add_executable(addproject main.c)
include_directories(include)
link_directories(lib)
target_link_libraries(addproject add.a)
Then when I run cmake . , it generates the makefile correctly.
But when I run make, I receive a linker error
Scanning dependencies of target addproject
[ 50%] Building C object CMakeFiles/addproject.dir/main.c.o
[100%] Linking C executable addproject
ld: library not found for -ladd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [addproject] Error 1
make[1]: *** [CMakeFiles/addproject.dir/all] Error 2
make: *** [all] Error 2
Stating it can't find library for add? Even though I set library_directories in cmake.. Can someone help me fix this error?
Thanks!