Help with using cURL in ESP32 Project

souler
Posts: 4
Joined: Sun May 26, 2024 12:01 am

Help with using cURL in ESP32 Project

Postby souler » Sun May 26, 2024 1:23 am

Hello, I'm working on an ESP32 project and having some trouble integrating cURL.
Initially, my project structure looked like this:

Code: Select all

Project
├── MyLibs/
│   ├── rol.h
│   ├── web.h
│   ├── APImain.h
├── second/
│   ├── Rol/
│   │   ├── roles.c
│   │   └── CMakeLists.txt
│   └── API/
│       ├── APImain.c
│       └── CMakeLists.txt
├── main/
│   ├── main.c
│   └── CMakeLists.txt
└── CMakeLists.txt
I had some problems getting my project to detect curl, so to make it work I added the curl folder to my project:

Code: Select all

Project
├── MyLibs/
│   ├── cURL/
│   │   ├── include/
│   │   │   ├── curl/
│   │   │   │   ├── curl.h
│   │   │   │   └── ...
│   │   │   ├── lib/
│   │   │   │   ├── libcurl.a
│   │   │   │   └── ...
│   │   │   └── ...
│   │   └── ...
│   ├── rol.h
│   ├── web.h
│   ├── APImain.h
├── second/
│   ├── Rol/
│   │   ├── roles.c
│   │   └── CMakeLists.txt
│   └── API/
│       ├── APImain.c
│       └── CMakeLists.txt
├── main/
│   ├── main.c
│   └── CMakeLists.txt
└── CMakeLists.txt
This change works fine for me but now I have the problem that it does not detect some curl functions:
undefined reference to 'curl_easy_init'
undefined reference to 'curl_easy_setopt'
These are some examples, in my APImain.c file I have this:

Code: Select all

  #include "cURL/include/curl/curl.h"
I tried adding things to the CMake files but despite several tests I still get the same error

Code: Select all

c:/users/luis_/.espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/12.2.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(APImain.c.obj):(.literal.POSTdata+0x3c): undefined reference to `curl_easy_init'
I was thinking if I should add the curl folder or files to the expressif tools.

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Help with using cURL in ESP32 Project

Postby MicroController » Sun May 26, 2024 11:57 am

souler wrote:
Sun May 26, 2024 1:23 am
I tried adding things to the CMake files but despite several tests I still get the same error
That's the right approach. Make sure you define the include paths correctly and include cURL's sources in the build, or if you already have the lib precompiled for your ESP tell the linker that you want it linked in, see e.g https://docs.espressif.com/projects/esp ... components

Alternatively, you can look into doing away with cURL and just use the ESP-IDF HTTP client.

souler
Posts: 4
Joined: Sun May 26, 2024 12:01 am

Re: Help with using cURL in ESP32 Project

Postby souler » Mon May 27, 2024 5:15 am

MicroController wrote:
Sun May 26, 2024 11:57 am
That's the right approach. Make sure you define the include paths correctly and include cURL's sources in the build, or if you already have the lib precompiled for your ESP tell the linker that you want it linked in, see e.g https://docs.espressif.com/projects/esp ... components

Alternatively, you can look into doing away with cURL and just use the ESP-IDF HTTP client.
I downloaded curl from the website, specifically cURL 8.8.0 for Windows. My understanding is that the .a files indicate that it is a precompiled version since the lib/ folder contains libcurl.a and libcurl.dll.a.

What should I put in the cmake files? Should I add instructions to the root cmake file?

in cmake root

Code: Select all

cmake_minimum_required(VERSION 3.16)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(ProyectoESP)
 


in cmake from APImain.c

Code: Select all

idf_component_register(SRCS "APImain.c"
                      INCLUDE_DIRS "." "../../MyLibs" 
                  REQUIRES  MyLibs )
and cmake from main.c

Code: Select all

idf_component_register(SRCS "main.c" "../second/Roles/roles.c"  "../second/API/APImain.c"
                            INCLUDE_DIRS       
                                    "../MyLibs"
                                    "../MyLibs/cURL"
                                   )     
When it starts to fail the first thing that appears is this:

Code: Select all

[2/4] Linking CXX executable ProyectoESP.elf
FAILED: ProyectoESP.elf
I have modified the cmake files several times to indicate the curl path but I always return them as I showed before because I get other problems and I am new to using cmake

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Help with using cURL in ESP32 Project

Postby MicroController » Mon May 27, 2024 12:12 pm

cURL 8.8.0 for Windows
is of no use for an ESP32.

Who is online

Users browsing this forum: No registered users and 104 guests