raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.27k stars 848 forks source link

Error when linking agasit mbedtls "fatal error: lwip/opt.h: No such file or directory" #1140

Closed locnnil closed 1 year ago

locnnil commented 1 year ago

I'm trying to use Mbed-TLS library on Raspberry Pi Pico board. But after following the instructions in @peterharperuk commit (450a4d5) that fixes #894 I'm noting beeing able to compile my aplication when linking with pico_lwip_mbedtls and pico_mbedtls.

On my linking libraries I've selected:

    target_link_libraries(${PROJECT_NAME} 
        pico_stdlib 
        pico_stdio 
        hardware_uart 
        hardware_irq
        pico_lwip_mbedtls
        pico_mbedtls
        )

If I remove pico_mbedtls and pico_lwip_mbedtls it compiles fine.

NOTE: I'm not using any functionality of mbedtls yet. I'm just trying to check if it works.

NOTE 2: My system infos:

# uname -a
Linux pop-os 6.0.6-76060006-generic #202210290932~1669062050~22.04~d94609a SMP PREEMPT_DYNAMIC Mon N x86_64 x86_64 x86_64 GNU/Linux

# CMake
cmake version 3.22.1

# GCC version
arm-none-eabi-gcc (15:10.3-2021.07-4) 10.3.1 20210621 (release)

EDIT: I'm using the last version of pico-sdk version 1.4.0, on commit 2e6142b.

locnnil commented 1 year ago

I solved this issue by cross-compiling MbedTLS myself and linking it against my generated .uf2 file, as I explained in this issue in the MbedTLS repository.

underhood commented 1 year ago

~seem to be having exact same issue. Is there a way to make it work with pico-sdk? (without compiling own MbedTLS?)~

For people who will google and find this (as I did) In my case issue seemed to be trying to use it with pico_cyw43_arch_none switching to pico_cyw43_arch_lwip_threadsafe_background seems to have fixed the issue

peterharperuk commented 1 year ago

Let's see if we can make it more obvious. And you should be able to use mbedtls without lwip?

locnnil commented 1 year ago

@peterharperuk In most part I think that yes. Because, acording with my researches lwIP is a "open-source TCP/IP stack designed for embedded systems" right? But in my case I wish to use mbedtls for radio ( RF ) aplications and not TCP/IP or other socket aplication, my goal was basically ensure a secure encrypted RF transmission.

peterharperuk commented 1 year ago

Correct. I've only every used it with an IP stack but I'd expect it to be possible.

kilograham commented 1 year ago

um a bit confused: yes we should be able to link against mbedtls without lwip, but why are you including both

 pico_lwip_mbedtls
 pico_mbedtls

?

if you don't want lwip, just use pico_mbedtls (no i haven't tried it, but your error above comes from trying to compile pico_lwip_mbedtls)

locnnil commented 1 year ago

@kilograham What you said seems very logic, I agree with you, but when I just tried to add pico_mbedtls at target_link_libraries seems that the linker couldn't find the library:

[build] Scanning dependencies of target crypto_lock
[build] Consolidate compiler generated dependencies of target crypto_lock
[build] [ 20%] Linking CXX executable crypto_lock.elf
[build] /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: cannot find -lpico_mbedtls: No such file or directory
[build] collect2: error: ld returned 1 exit status
[build] gmake[2]: * [CMakeFiles/crypto_lock.dir/build.make:1449: crypto_lock.elf] Error 1
[build] gmake[1]: * [CMakeFiles/Makefile2:1491: CMakeFiles/crypto_lock.dir/all] Error 2
[build] gmake: * [Makefile:91: all] Error 2
[proc] The command: /usr/bin/cmake --build /home/lincoln/TFG/lock/build --config Debug --target all -j 6 -- exited with code: 2
[build] Build finished with exit code 2

I think this linking error is because I'm doing something wrong.

About my setup: I check in git log and I'm currently in the latest commit at master f396d05

peterharperuk commented 1 year ago

I can't reproduce this. I seem to be able to use pico_medbtls on its own without any issue. It's possible we've fixed something while implementing other changes.

peterharperuk commented 1 year ago

My example is here https://github.com/peterharperuk/pico-examples/tree/mbedtls_example If anyone can repro this, please reopen.