-1

I'm trying to get CMake under CLion to build a simple program that links with the curl library. From the command line it builds like this:

gcc main.c -l curl

I can't get CMake to link with the curl library however:

cmake_minimum_required(VERSION 3.15)
project(http_examples_c C)

set(CMAKE_C_STANDARD 99)

add_executable(http_examples_c main.c)
target_link_libraries(/usr/lib/x86_64-linux-gnu/libcurl.a)

How do I tell CMake to just link with the curl library?

Dean Schulze
  • 9,633
  • 24
  • 100
  • 165

1 Answers1

2

When using target_link_libraries(), you need to tell CMake to link the library to a specific target you have already defined. Try something like this instead:

target_link_libraries(http_examples_c PUBLIC /usr/lib/x86_64-linux-gnu/libcurl.a)

As commented, you shouldn't need to put the full path to the curl library in your system path, unless you are trying to let CMake choose this curl library over another curl library that may also be in your system. Given your gcc command simply used curl, you could likely simplify this call to:

target_link_libraries(http_examples_c PUBLIC curl)
Kevin
  • 16,549
  • 8
  • 60
  • 74