I'm learning about Cmake and adding library projects in simple C projects. I have created a simple Library project with the following structure.
MyLibraryProjectDirectory
|
-- library.C
-- library.h
-- UmerDir
|
-- Umer.h
-- Umer.c
The Cmakelist.txt is generating a .a lib
file that I'm using in another C program.
The C Program is structured like this:
MyCProgram
|
-- main.c
-- libuntitled.a
libuntitled.a
is the library file generated by CmakeList.txt in my library project.
The problem is when I try to build the C project with the .a
file, it throws the following
ERRORS:
"C:\Program Files\JetBrains\CLion 2017.2\bin\cmake\bin\cmake.exe" --build C:\Users\Lenovo\CLionProjects\AppProject\cmake-build-debug --target AppProject -- -j 2
[ 50%] Linking C executable AppProject.exe
C:/mingw-w64/i686-7.1.0-posix-dwarf-rt_v5-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -llibuntitled
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [AppProject.exe] Error 1
CMakeFiles\AppProject.dir\build.make:95: recipe for target 'AppProject.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/AppProject.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/AppProject.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/AppProject.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/AppProject.dir/rule' failed
mingw32-make.exe: *** [AppProject] Error 2
Makefile:117: recipe for target 'AppProject' failed
I'm not sure what I'm doing wrong, so please excuse my extremely limited knowledge in CMake and C build systems.
I'm also attaching the screenshots of the C Program and C library Project for convenience.
Library Project Screenshots:
C Program Project:
EDIT:
I have fixed the library not found problem by adding ${CMAKE_SOURCE_DIR}
before .a library name. Apparently Cmake needed the full classified path to locate the .a file even in the same directory, which is kinda weird. Anyways, now I'm getting the following error:
ERROR:
"C:\Program Files\JetBrains\CLion 2017.2\bin\cmake\bin\cmake.exe" --build C:\Users\Lenovo\CLionProjects\AppProject\cmake-build-debug --target AppProject -- -j 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/AppProject.dir/all' failed
mingw32-make.exe[3]: *** No rule to make target '../libuntitled', needed by 'AppProject.exe'. Stop.
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/AppProject.dir/rule' failed
mingw32-make.exe[2]: *** [CMakeFiles/AppProject.dir/all] Error 2
Makefile:117: recipe for target 'AppProject' failed
mingw32-make.exe[1]: *** [CMakeFiles/AppProject.dir/rule] Error 2
mingw32-make.exe: *** [AppProject] Error 2
mingw32-make.exe3: No rule to make target '../libuntitled', needed by 'AppProject.exe'. Stop.