-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?

0

1 Answer 1

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) 
Sign up to request clarification or add additional context in comments.

2 Comments

Just target_link_libraries(http_examples_c PUBLIC curl)
@KamilCuk Good catch, updated the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.