0

I am trying to build liboqs (https://github.com/open-quantum-safe/liboqs) on Ubuntu to use as a library on STM32L432. I successfully ran cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=../.CMake/toolchain_armel.cmake -DOQS_USE_OPENSSL=OFF .. and after running ninja I get the below error.

/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld:
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc.a(lib_a-aligned_alloc.o): in function `aligned_alloc':
/build/newlib-CVVEyx/newlib-3.3.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/aligned_alloc.c:35: undefined reference to `posix_memalign'
collect2: error: ld returned 1 exit status

ninja generated this command that gives the above error.

/usr/bin/arm-none-eabi-gcc    src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600_plain64.dir/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c.o src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600times4_serial.dir/KeccakP-1600times4/serial/KeccakP-1600-times4-on1.c.o src/common/CMakeFiles/common.dir/aes/aes.c.o src/common/CMakeFiles/common.dir/aes/aes_c.c.o src/common/CMakeFiles/common.dir/sha2/sha2.c.o src/common/CMakeFiles/common.dir/sha2/sha2_c.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3x4.c.o src/common/CMakeFiles/common.dir/common.c.o src/common/CMakeFiles/common.dir/pqclean_shims/nistseedexpander.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202x4.c.o src/common/CMakeFiles/common.dir/rand/rand.c.o src/common/CMakeFiles/common.dir/rand/rand_nist.c.o tests/CMakeFiles/test_aes.dir/test_aes.c.o  -o tests/test_aes  -lm -specs=nosys.specs

arm-none-eabi-gcc --version

arm-none-eabi-gcc (15:9-2019-q4-0ubuntu1) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
Copyright (C) 2019 Free Software Foundation, Inc.

dpkg --status libnewlib-arm-none-eabi

Package: libnewlib-arm-none-eabi
Status: install ok installed
Priority: optional
Section: libs
Installed-Size: 576826
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Source: newlib
Version: 3.3.0-0ubuntu1
Depends: libnewlib-dev (= 3.3.0-0ubuntu1)
Recommends: gcc-arm-none-eabi, libstdc++-arm-none-eabi-newlib
Suggests: libnewlib-doc

cmake --build ./ --verbose

[1/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/sig_dilithium_5_aes.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/sig_dilithium_5_aes.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/sig_dilithium_5_aes.c.o   -c ../src/sig/dilithium/sig_dilithium_5_aes.c
[2/381] : && /usr/bin/arm-none-eabi-gcc --specs=nosys.specs   src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600_plain64.dir/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c.o src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600times4_serial.dir/KeccakP-1600times4/serial/KeccakP-1600-times4-on1.c.o src/common/CMakeFiles/common.dir/aes/aes.c.o src/common/CMakeFiles/common.dir/aes/aes_c.c.o src/common/CMakeFiles/common.dir/sha2/sha2.c.o src/common/CMakeFiles/common.dir/sha2/sha2_c.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3x4.c.o src/common/CMakeFiles/common.dir/common.c.o src/common/CMakeFiles/common.dir/pqclean_shims/nistseedexpander.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202x4.c.o src/common/CMakeFiles/common.dir/rand/rand.c.o src/common/CMakeFiles/common.dir/rand/rand_nist.c.o tests/CMakeFiles/test_aes.dir/test_aes.c.o  -o tests/test_aes  -lm && :
FAILED: tests/test_aes 
: && /usr/bin/arm-none-eabi-gcc --specs=nosys.specs   src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600_plain64.dir/KeccakP-1600/plain-64bits/KeccakP-1600-opt64.c.o src/common/sha3/xkcp_low/CMakeFiles/xkcp_low_keccakp_1600times4_serial.dir/KeccakP-1600times4/serial/KeccakP-1600-times4-on1.c.o src/common/CMakeFiles/common.dir/aes/aes.c.o src/common/CMakeFiles/common.dir/aes/aes_c.c.o src/common/CMakeFiles/common.dir/sha2/sha2.c.o src/common/CMakeFiles/common.dir/sha2/sha2_c.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3.c.o src/common/CMakeFiles/common.dir/sha3/xkcp_sha3x4.c.o src/common/CMakeFiles/common.dir/common.c.o src/common/CMakeFiles/common.dir/pqclean_shims/nistseedexpander.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202.c.o src/common/CMakeFiles/common.dir/pqclean_shims/fips202x4.c.o src/common/CMakeFiles/common.dir/rand/rand.c.o src/common/CMakeFiles/common.dir/rand/rand_nist.c.o tests/CMakeFiles/test_aes.dir/test_aes.c.o  -o tests/test_aes  -lm && :
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/libc.a(lib_a-aligned_alloc.o): in function `aligned_alloc':
/build/newlib-CVVEyx/newlib-3.3.0/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/aligned_alloc.c:35: undefined reference to `posix_memalign'
collect2: error: ld returned 1 exit status
[3/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium2aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=2 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/symmetric-aes.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/symmetric-aes.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/symmetric-aes.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium2aes_ref/symmetric-aes.c
[4/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/ntt.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/ntt.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/ntt.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/ntt.c
[5/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/reduce.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/reduce.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/reduce.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/reduce.c
[6/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/rounding.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/rounding.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/rounding.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/rounding.c
[7/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium2aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=2 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/sign.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/sign.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_2_aes_ref.dir/pqcrystals-dilithium_dilithium2aes_ref/sign.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium2aes_ref/sign.c
[8/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/packing.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/packing.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/packing.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/packing.c
[9/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/polyvec.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/polyvec.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/polyvec.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/polyvec.c
[10/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/sign.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/sign.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/sign.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/sign.c
[11/381] /usr/bin/arm-none-eabi-gcc  -Iinclude -I../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref -I../src/common/pqclean_shims --specs=nosys.specs -fPIC -fvisibility=hidden   -Wa,--noexecstack -O3 -fomit-frame-pointer -fdata-sections -ffunction-sections -Wl,--gc-sections -DDILITHIUM_MODE=5 -DDILITHIUM_USE_AES -DDILITHIUM_RANDOMIZED_SIGNING -std=gnu11 -MD -MT src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/poly.c.o -MF src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/poly.c.o.d -o src/sig/dilithium/CMakeFiles/dilithium_5_aes_ref.dir/pqcrystals-dilithium_dilithium5aes_ref/poly.c.o   -c ../src/sig/dilithium/pqcrystals-dilithium_dilithium5aes_ref/poly.c
ninja: build stopped: subcommand failed.

The following sample code compiles fine using arm-none-eabi-gcc -specs=nosys.specs test.c

#include <stdlib.h> int main() {aligned_alloc(1, 1);}

The following sample code gives error:

#include <stdlib.h> int main() {posix_memalign(NULL, 1, 1);}

I am getting the following error while running the following command on the above posix_memalign code:

arm-none-eabi-gcc -specs=nosys.specs test2.c --verbose

Using built-in specs.
Reading specs from /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/nosys.specs
rename spec link_gcc_c_sequence to nosys_link_gcc_c_sequence
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: /mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/src/gcc/configure --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native --libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/lib --infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/arm-none-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Arm Embedded Toolchain 10.3-2021.10' --with-multilib-list=rmprofile,aprofile
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10) 
COLLECT_GCC_OPTIONS='-specs=nosys.specs' '-v' '-mcpu=arm7tdmi' '-mfloat-abi=soft' '-marm' '-mlibarch=armv4t' '-march=armv4t'
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/cc1 -quiet -v -iprefix /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/ -isysroot /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi -D__USES_INITFINI__ test2.c -quiet -dumpbase test2.c -mcpu=arm7tdmi -mfloat-abi=soft -marm -mlibarch=armv4t -march=armv4t -auxbase test2 -version -o /tmp/cchF0Wd9.s
GNU C17 (GNU Arm Embedded Toolchain 10.3-2021.10) version 10.3.1 20210824 (release) (arm-none-eabi)
    compiled by GNU C version 4.8.4, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/10.3.1/include"
ignoring nonexistent directory "/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi/usr/local/include"
ignoring duplicate directory "/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/10.3.1/include-fixed"
ignoring duplicate directory "/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/include"
ignoring nonexistent directory "/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/include
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/include-fixed
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/include
End of search list.
GNU C17 (GNU Arm Embedded Toolchain 10.3-2021.10) version 10.3.1 20210824 (release) (arm-none-eabi)
    compiled by GNU C version 4.8.4, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ada28fdd13bdd399f195284d34df0081
test2.c: In function 'main':
test2.c:8:5: warning: ignoring return value of 'posix_memalign' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     posix_memalign(NULL, 1, 1);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
COLLECT_GCC_OPTIONS='-specs=nosys.specs' '-v' '-mcpu=arm7tdmi' '-mfloat-abi=soft' '-marm' '-mlibarch=armv4t' '-march=armv4t'
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/as -v -march=armv4t -mfloat-abi=soft -meabi=5 -o /tmp/cc6SFJj8.o /tmp/cchF0Wd9.s
GNU assembler version 2.36.1 (arm-none-eabi) using BFD version (GNU Arm Embedded Toolchain 10.3-2021.10) 2.36.1.20210621
COMPILER_PATH=/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/:/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/:/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/
LIBRARY_PATH=/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/:/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/:/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/:/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi/lib/
COLLECT_GCC_OPTIONS='-specs=nosys.specs' '-v' '-mcpu=arm7tdmi' '-mfloat-abi=soft' '-marm' '-mlibarch=armv4t' '-march=armv4t'
 /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/collect2 -plugin /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/liblto_plugin.so -plugin-opt=/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper -plugin-opt=-fresolution=/tmp/cctHZek9.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lnosys --sysroot=/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi -X /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/crti.o /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/crtbegin.o /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/crt0.o -L/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1 -L/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc -L/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib -L/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../arm-none-eabi/lib /tmp/cc6SFJj8.o --start-group -lgcc -lc --end-group --start-group -lgcc -lc -lnosys --end-group /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/crtend.o /usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/crtn.o
/usr/share/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /tmp/cc6SFJj8.o: in function `main':
test2.c:(.text+0x14): undefined reference to `posix_memalign'
collect2: error: ld returned 1 exit status

Question: How can I fix the error: Undefined reference to `posix_memalign'?

tarun14110
  • 940
  • 5
  • 26
  • 57
  • 1
    What arm-none-eabi-gcc version, and newlib version arey ou using? What compile flags and options are you using? Please post the full output of `cmake --build --verbose`. – KamilCuk May 13 '23 at 18:58
  • @KamilCuk added the details. – tarun14110 May 13 '23 at 19:45
  • Let's take that liboqs out of the picture. Please create a small `test.c` file with `#include int main() { aligned_alloc(1, 1); }` and see if it compiles with `arm-none-eabi-gcc -specs=nosys.specs`? What about similar short code with `posix_memalign`? `newlib Version: 3.3.0` do an update. There is no question in your post. Consider asking a question. It is unclear to me what exactly are you having a problem with. – KamilCuk May 13 '23 at 21:46
  • @KamilCuk Thanks for your help. I added the compilation results of sample codes. `aligned_alloc` runs fine. `posix_memalign` gives the same undefined reference error. I assumed newlib 3.3.0 is the latest stable version based on https://launchpad.net/ubuntu/+source/newlib. What is the version you recommend installing? My question is "How can I fix undefined reference to `posix_memalign' error?" – tarun14110 May 14 '23 at 02:01
  • I think this issue might have been resolved in `newlib` version https://github.com/devkitPro/newlib/issues/7.I am trying to install new version of newlib from source on github by running `./configure --target=arm-none-eabi --prefix=/usr/lib/ && make && make install`, but do not see the installed newlib. – tarun14110 May 14 '23 at 04:59
  • https://developer.arm.com/downloads/-/gnu-rm – KamilCuk May 14 '23 at 06:14

1 Answers1

0

How can I fix the error: Undefined reference to `posix_memalign'?

You can:

  • implement your own version of posix_memalign function
  • use a different implementation of C standard library that comes with this functions
  • use a library that implements the function

Bottom line, there is no posix_memalign function in newlib.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111