0

I have a very simple Cmake List. I recently learned that to use pow(), we have to link libraires, therefore i run target_link_libraries Below is my CMakeList.txt

cmake_minimum_required(VERSION 3.21)
project(code C)

set(CMAKE_C_STANDARD 99)

add_executable(custom_malloc_and_free asn4/custom_malloc_and_free.c)
target_link_libraries(custom_malloc_and_free asn4/custom_malloc_and_free.c)

(project sturcture - my code custom_malloc_and_free.c is located in the directory asn4) I get the error

[100%] Linking C executable custom_malloc_and_free
/usr/bin/ld: cannot find -lasn4/custom_malloc_and_free.c
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/custom_malloc_and_free.dir/build.make:97: custom_malloc_and_free] Error 1
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/custom_malloc_and_free.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/custom_malloc_and_free.dir/rule] Error 2
make: *** [Makefile:124: custom_malloc_and_free] Error 2

What error is this? I tried fixing it this but I have no clue what to do.

  • [`target_link_libraries`](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) gives you a way to specify what libraries need to be linked to a given target. A C source file is not a library. Do consult the documentation (linked). – John Bollinger Mar 24 '22 at 14:14

0 Answers0