# Trying to statically link curl directory for CMake on Linux: undefined reference to \`curl\_easy\_init'

**URL:** https://discourse.cmake.org/t/trying-to-statically-link-curl-directory-for-cmake-on-linux-undefined-reference-to-curl-easy-init/8835
**Category:** Usage
**Created:** [August 29, 2023, 8:10am UTC](https://discourse.cmake.org/t/trying-to-statically-link-curl-directory-for-cmake-on-linux-undefined-reference-to-curl-easy-init/8835 "2023-08-29T08:10:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![HallofFamer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HallofFamer](https://discourse.cmake.org/u/HallofFamer)
#### Post date: [August 29, 2023, 8:10am UTC](https://discourse.cmake.org/t/trying-to-statically-link-curl-directory-for-cmake-on-linux-undefined-reference-to-curl-easy-init/8835/1 "2023-08-29T08:10:09Z")

</div>

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:

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 29, 2023, 2:18pm UTC](https://discourse.cmake.org/t/trying-to-statically-link-curl-directory-for-cmake-on-linux-undefined-reference-to-curl-easy-init/8835/2 "2023-08-29T14:18:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![HallofFamer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HallofFamer](https://discourse.cmake.org/u/HallofFamer)
#### Post date: [August 29, 2023, 5:09pm UTC](https://discourse.cmake.org/t/trying-to-statically-link-curl-directory-for-cmake-on-linux-undefined-reference-to-curl-easy-init/8835/3 "2023-08-29T17:09:12Z")

</div>

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

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

```
