Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Using std::this_thread::sleep_for on Raspberry Pi Pico

$
0
0

when I add this line of code to my project

std::this_thread::sleep_for(10ms);

I get this linker error

./build/thumb/v6-m/nofp/libstdc++/src/c++11/../../../../../../../src/libstdc++-v3/src/c++11/thread.cc:228: undefined reference to `usleep'/usr/lib/gcc/arm-none-eabi/12.2.1/../../../arm-none-eabi/bin/ld: ./build/thumb/v6-m/nofp/libstdc++/src/c++11/../../../../../../../src/libstdc++-v3/src/c++11/thread.cc:238: undefined reference to `sleep'/usr/lib/gcc/arm-none-eabi/12.2.1/../../../arm-none-eabi/bin/ld: ./build/thumb/v6-m/nofp/libstdc++/src/c++11/../../../../../../../src/libstdc++-v3/src/c++11/thread.cc:238: undefined reference to `sleep'collect2: error: ld returned 1 exit status

I've tried fixing this error by adding...

void usleep(uint64_t microseconds) {    sleep_us(microseconds);}

but I'm not sure if I have the signature right or if it's even possible(or appropriate) to fix the problem with this approach. Does anyone know how to correct this? Or am I just stuck switching all of my std::this_thread::sleep_for's to sleep_us's to get my code working on the pico?

EDIT: I was able to find this code, it fixes the problem

extern "C" {int usleep(useconds_t microseconds) {    sleep_us(microseconds);    return 0;}unsigned int sleep(unsigned int seconds) {    sleep_ms(seconds * 1000);    return 0;}}

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>