Trying to statically link curl directory for CMake on Linux: undefined reference to `curl_easy_init'

I am able to get CMake to work on Windows, and on Linux I am struggling with CURL. Cant get vcpkg to work there, and I’ve decided to use static linking instead as its safe to assume most linux users do not change the default installation path for Curl/LibCurl. However, the code below does not seem to work:

    set(CURL_LIBRARY "-lcurl")
    set(CURL_INCLUDE_DIR "/usr/include/x86_64-linux-gnu")
    find_package(CURL REQUIRED)

I can see curl.h and curl.c in the directory “/usr/include/x84_64-linux-gnu/curl”, trying to change this to “/usr/bin” or “usr/bin/curl” does not seem to work either. I keep getting undefined reference to curl_easy_init, and undefined reference to curl_easy_set_opt error messages. How can I fix this issue?

Have you tried not setting CURL_* variables before doing find_package(CURL). You may also want to try linking to CURL::CURL instead of using variables.

Are you suggesting using find_package(CURL) before setting curl library and include path? I think I can try that. And can you explain what you mean by linking to CURL::CURL? It’s a pure C project though.

Edit: nvm, this code below works for me

    find_package(CURL REQUIRED)
    target_link_libraries(${PROJECT_NAME} CURL::libcurl)