Using curl library (nrf/ext/curl)

I would like to use the cURL libary that is included in the nRF Connect SDK (v2.6.1) a nrf/ext/curl

I started with the download sample (nrf/samples/net/download)

I've added this to CMakeLists.txt

# CMakeLists.txt

# ...
target_include_directories(app PRIVATE C:/ncs/v2.6.1/nrf/ext/curl/include/)
# ...

And I've added this to the top of src.main.c:

// src/main.c
// ...
#include <string.h>
#include <stdlib.h>
#include <zephyr/kernel.h>
#include <zephyr/net/socket.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/conn_mgr_connectivity.h>
#include <net/download_client.h>

#include <curl/curl.h>

// ...

When I build, I get the following error: 

In file included from C:/ncs/v2.6.1/nrf/ext/curl/include/curl/curl.h:38,
from C:/Users/MarkBlackburn/Documents/git/nrf9160_samples/curl_test/src/main.c:15:
C:/ncs/v2.6.1/nrf/ext/curl/include/curl/system.h:436:12: fatal error: sys/socket.h: No such file or directory
436 | # include <sys/socket.h>


How do I get the sys/socket.h file included in the project?

  • Hi,

    Which board do you use?

    Can you provide your build command?

    Best regards,
    Dejan

  • I'm using nrf9160dk_nrf9160_ns.

    Here's the build command VS Code generated:

    west build --build-dir c:/Users/MarkBlackburn/Documents/git/nrf9160_samples/curl_test/build_dk c:/Users/MarkBlackburn/Documents/git/nrf9160_samples/curl_test --pristine --board nrf9160dk_nrf9160_ns --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DBOARD_ROOT=c:/users/markblackburn/board-roots;c:/users/markblackburn/documents/git/nrf9160_samples/curl_test

    I had earlier renamed the download sample to curl_test

    I've updated CMakeLists.txt to add the folder for the sys/socket.h include. Now I'm stuck on link errors as I don't know how to add the .c files for the nrf/ext/curl folder.

    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/../nrf/ext/curl/include/)
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/include/zephyr/posix/)

  • Hi,

    You could try out the changes shown below and build for nrf9160dk_nrf9160_ns board target.

    CMakeLists.txt

    target_sources(app PRIVATE src/main.c)
    target_include_directories(app PRIVATE C:/ncs/v2.6.1/nrf/ext/curl/include/)


    main.c
    #if !defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
    #include <zephyr/posix/sys/socket.h>
    #else
    #include <zephyr/net/socket.h>
    #endif
    
    #include <nrf_curl.h>


    prj.conf
    #
    # Copyright (c) 2021 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    CONFIG_DOWNLOAD_CLIENT=y
    CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_CONNECTION_MANAGER=y
    CONFIG_NET_SOCKETS=y
    #CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_IPV4=y
    CONFIG_HEAP_MEM_POOL_SIZE=1024
    
    
    CONFIG_POSIX_API=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NRF_CURL=y
    CONFIG_PTHREAD_IPC=n
    CONFIG_NRF_CURL_INTEGRATION=y
    

    Best regards,
    Dejan

Related