交叉编译配置时找不到 nanosleep 函数

cannot find the nanosleep function when cross compile configure

我使用 here 的工具链,然后提取到 gcc11_arm_armv7_none_gnueabihf、

下面是命令:

export ASFLAGS='-march=armv7-a -fPIC -fstack-protector -Wall -fno-omit-frame-pointer --sysroot=gcc11_arm_armv7_none_gnueabihf/arm-none-linux-gnueabihf/libc -no-canonical-prefixes  -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted -g3'
export CFLAGS='-march=armv7-a -fPIC -fstack-protector -Wall -fno-omit-frame-pointer --sysroot=gcc11_arm_armv7_none_gnueabihf/arm-none-linux-gnueabihf/libc -std=c99 -no-canonical-prefixes  -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted -g3'
export CXXFLAGS='-march=armv7-a -fPIC -fstack-protector -Wall -fno-omit-frame-pointer --sysroot=gcc11_arm_armv7_none_gnueabihf/arm-none-linux-gnueabihf/libc -std=c++11 -no-canonical-prefixes  -Wno-builtin-macro-redefined -D__DATE__=redacted -D__TIMESTAMP__=redacted -D__TIME__=redacted -g3'
export LDFLAGS='-lstdc++ -Wl,-z,relro,-z,now -pass-exit-codes -lm -Wall --sysroot=gcc11_arm_armv7_none_gnueabihf/arm-none-linux-gnueabihf/libc -lpthread'

export AR=gcc11_arm_armv7_none_gnueabihf/bin/arm-none-linux-gnueabihf-gcc-ar
export CC=gcc11_arm_armv7_none_gnueabihf/bin/arm-none-linux-gnueabihf-gcc
export CXX=gcc11_arm_armv7_none_gnueabihf/bin/arm-none-linux-gnueabihf-gcc
export LD=gcc11_arm_armv7_none_gnueabihf/bin/arm-none-linux-gnueabihf-ld
./configure
......
......
checking if nanosleep requires any libraries... configure: error: cannot find the nanosleep function

我可以在 gcc11_arm_armv7_none_gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/time.h 中找到 nanosleep 函数,但它是一个外部声明,我是否需要向编译器传递一些内容以让它知道在哪里可以找到 nanosleep 定义?

nanosleep 需要 _POSIX_C_SOURCE >= 199309Lman nanosleep 指定的特征宏。

尝试在 #include <time.h> 之前添加 #define _POSIX_C_SOURCE 199309L