如何为arm gcc构建MBEDTL

如何为arm gcc构建MBEDTL,arm,stm32,freertos,mbedtls,Arm,Stm32,Freertos,Mbedtls,我想在stm32项目中使用mbedtls,但在构建时遇到了一些问题。 我必须用arm none gcc编译器构建mbedtls,对吗? 我的命令是:(在build目录中) 我在编译测试程序时出错: none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc CFLAGS='-fstack-protector-strong' cmake - DUSE_SHARED_MBEDTLS_LIBRARY=On ../ -- The C compiler identi

我想在stm32项目中使用mbedtls,但在构建时遇到了一些问题。 我必须用arm none gcc编译器构建mbedtls,对吗? 我的命令是:(在build目录中)

我在编译测试程序时出错:

none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc CFLAGS='-fstack-protector-strong' cmake - 
DUSE_SHARED_MBEDTLS_LIBRARY=On ../
-- The C compiler identification is GNU 10.2.1
-- Check for working C compiler: 
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc
-- Check for working C compiler: 
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler

"/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_47d0a/fast && /usr/bin/make -f 
CMakeFiles/cmTC_47d0a.dir/build.make CMakeFiles/cmTC_47d0a.dir/build
make[1]: Entering directory 
'/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc   -fstack-protector-strong    -o 
CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o   -c 
/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS- 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_47d0a
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_47d0a.dir/link.txt --verbose=1
/home/jareeeeczek/Arczbit/Firmware/ProgramingRelated/ARM_GCC/gcc-arm-none-eabi-10-2020-q4- 
major/bin/arm-none-eabi-gcc -fstack-protector-strong     -rdynamic 
CMakeFiles/cmTC_47d0a.dir/testCCompiler.c.o  -o cmTC_47d0a 
arm-none-eabi-gcc: error: unrecognized command-line option '-rdynamic'
make[1]: *** [CMakeFiles/cmTC_47d0a.dir/build.make:87: cmTC_47d0a] Error 1
make[1]: Leaving directory 
'/home/jareeeeczek/Arczbit/Projects/Parkometr/software/FreeRtos/FreeRTOS  - 
Plus/ThirdParty/mbedtls/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_47d0a/fast] Error 2

有人知道为什么cmake在编译测试程序时有问题吗?

我认为您没有配置
mbedtls
以便为裸机系统构建它。一些默认选项需要禁用,因为您的目标不是通用操作系统:(没有文件系统,所以标准BSD套接字接口…)

这就是您无法编译测试程序的原因,也是您需要通过在cmake build命令中指定
-DENABLE_TESTING=OFF
来禁用其编译的原因

请参阅
mbedtls-2.25.0/include/mbedtls/config.h
中的大量有用注释,以获取有关各种可用配置选项的更多详细信息

下面描述的过程确实有效,您应该能够通过使用它作为工作示例来修改自己的构建过程

toochain.cmake

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR armv7-m)
set(CMAKE_STAGING_PREFIX /tmp/staging)
set(CMAKE_C_COMPILER /opt/arm/10/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER /opt/arm/10/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-g++)
set(CMAKE_MAKE_PROGRAM=/usr/bin/make)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_C_FLAGS=-mtune=cortex-m3)
set(CMAKE_EXE_LINKER_FLAGS " --specs=nosys.specs")
构建过程:

# extracting
tar zxf v2.25.0.tar.gz

# modifying default configuration using config.py:
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h set MBEDTLS_NO_PLATFORM_ENTROPY 1
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_FS_IO
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_STORAGE_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_TIMING_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_NET_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_CONFIG
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_ITS_FILE_C

# building:
mkdir mbedtls
pushd mbedtls
cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON -DENABLE_ZLIB_SUPPORT=OFF -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake ../mbedtls-2.25.0
make all install
popd

tree /tmp/staging
/tmp/staging
├── include
│   ├── mbedtls
│   │   ├── aes.h
│   │   ├── aesni.h
│   │   ├── arc4.h
│   │   ├── aria.h
│   │   ├── asn1.h
│   │   ├── asn1write.h
│   │   ├── base64.h
│   │   ├── bignum.h
│   │   ├── blowfish.h
│   │   ├── bn_mul.h
│   │   ├── camellia.h
│   │   ├── ccm.h
│   │   ├── certs.h
│   │   ├── chacha20.h
│   │   ├── chachapoly.h
│   │   ├── check_config.h
│   │   ├── cipher.h
│   │   ├── cipher_internal.h
│   │   ├── cmac.h
│   │   ├── compat-1.3.h
│   │   ├── config.h
│   │   ├── config_psa.h
│   │   ├── ctr_drbg.h
│   │   ├── debug.h
│   │   ├── des.h
│   │   ├── dhm.h
│   │   ├── ecdh.h
│   │   ├── ecdsa.h
│   │   ├── ecjpake.h
│   │   ├── ecp.h
│   │   ├── ecp_internal.h
│   │   ├── entropy.h
│   │   ├── entropy_poll.h
│   │   ├── error.h
│   │   ├── gcm.h
│   │   ├── havege.h
│   │   ├── hkdf.h
│   │   ├── hmac_drbg.h
│   │   ├── md2.h
│   │   ├── md4.h
│   │   ├── md5.h
│   │   ├── md.h
│   │   ├── md_internal.h
│   │   ├── memory_buffer_alloc.h
│   │   ├── net.h
│   │   ├── net_sockets.h
│   │   ├── nist_kw.h
│   │   ├── oid.h
│   │   ├── padlock.h
│   │   ├── pem.h
│   │   ├── pkcs11.h
│   │   ├── pkcs12.h
│   │   ├── pkcs5.h
│   │   ├── pk.h
│   │   ├── pk_internal.h
│   │   ├── platform.h
│   │   ├── platform_time.h
│   │   ├── platform_util.h
│   │   ├── poly1305.h
│   │   ├── psa_util.h
│   │   ├── ripemd160.h
│   │   ├── rsa.h
│   │   ├── rsa_internal.h
│   │   ├── sha1.h
│   │   ├── sha256.h
│   │   ├── sha512.h
│   │   ├── ssl_cache.h
│   │   ├── ssl_ciphersuites.h
│   │   ├── ssl_cookie.h
│   │   ├── ssl.h
│   │   ├── ssl_internal.h
│   │   ├── ssl_ticket.h
│   │   ├── threading.h
│   │   ├── timing.h
│   │   ├── version.h
│   │   ├── x509_crl.h
│   │   ├── x509_crt.h
│   │   ├── x509_csr.h
│   │   ├── x509.h
│   │   └── xtea.h
│   └── psa
│       ├── crypto_accel_driver.h
│       ├── crypto_compat.h
│       ├── crypto_config.h
│       ├── crypto_driver_common.h
│       ├── crypto_entropy_driver.h
│       ├── crypto_extra.h
│       ├── crypto.h
│       ├── crypto_platform.h
│       ├── crypto_se_driver.h
│       ├── crypto_sizes.h
│       ├── crypto_struct.h
│       ├── crypto_types.h
│       └── crypto_values.h
└── lib
    ├── libmbedcrypto.a
    ├── libmbedtls.a
    └── libmbedx509.a

4 directories, 96 files

我通过向mbedtls Cmake添加以下行解决了此问题:

设置(CMAKE_共享_库_链接_C_标志“”) 设置(CMAKE_共享_库_链接_CXX_标志“”)


谢谢你的帮助

告诉您错误所在的那一行是“错误:无法识别的命令行选项”-rdynamic'@Arkadiusz Bryń:答案有用吗?是否需要澄清/改进?如果是,您希望如何修改/改进?反馈将大大被损坏-谢谢。Hy@ Akadiuz Bry:如果这个或任何答案已经解决了你的问题,请考虑点击检查标记。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。当然,没有义务这样做。
# extracting
tar zxf v2.25.0.tar.gz

# modifying default configuration using config.py:
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h set MBEDTLS_NO_PLATFORM_ENTROPY 1
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_FS_IO
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_STORAGE_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_TIMING_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_NET_C
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_CRYPTO_CONFIG
mbedtls-2.25.0/scripts/config.py --file mbedtls-2.25.0/include/mbedtls/config.h unset MBEDTLS_PSA_ITS_FILE_C

# building:
mkdir mbedtls
pushd mbedtls
cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON -DENABLE_ZLIB_SUPPORT=OFF -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake ../mbedtls-2.25.0
make all install
popd

tree /tmp/staging
/tmp/staging
├── include
│   ├── mbedtls
│   │   ├── aes.h
│   │   ├── aesni.h
│   │   ├── arc4.h
│   │   ├── aria.h
│   │   ├── asn1.h
│   │   ├── asn1write.h
│   │   ├── base64.h
│   │   ├── bignum.h
│   │   ├── blowfish.h
│   │   ├── bn_mul.h
│   │   ├── camellia.h
│   │   ├── ccm.h
│   │   ├── certs.h
│   │   ├── chacha20.h
│   │   ├── chachapoly.h
│   │   ├── check_config.h
│   │   ├── cipher.h
│   │   ├── cipher_internal.h
│   │   ├── cmac.h
│   │   ├── compat-1.3.h
│   │   ├── config.h
│   │   ├── config_psa.h
│   │   ├── ctr_drbg.h
│   │   ├── debug.h
│   │   ├── des.h
│   │   ├── dhm.h
│   │   ├── ecdh.h
│   │   ├── ecdsa.h
│   │   ├── ecjpake.h
│   │   ├── ecp.h
│   │   ├── ecp_internal.h
│   │   ├── entropy.h
│   │   ├── entropy_poll.h
│   │   ├── error.h
│   │   ├── gcm.h
│   │   ├── havege.h
│   │   ├── hkdf.h
│   │   ├── hmac_drbg.h
│   │   ├── md2.h
│   │   ├── md4.h
│   │   ├── md5.h
│   │   ├── md.h
│   │   ├── md_internal.h
│   │   ├── memory_buffer_alloc.h
│   │   ├── net.h
│   │   ├── net_sockets.h
│   │   ├── nist_kw.h
│   │   ├── oid.h
│   │   ├── padlock.h
│   │   ├── pem.h
│   │   ├── pkcs11.h
│   │   ├── pkcs12.h
│   │   ├── pkcs5.h
│   │   ├── pk.h
│   │   ├── pk_internal.h
│   │   ├── platform.h
│   │   ├── platform_time.h
│   │   ├── platform_util.h
│   │   ├── poly1305.h
│   │   ├── psa_util.h
│   │   ├── ripemd160.h
│   │   ├── rsa.h
│   │   ├── rsa_internal.h
│   │   ├── sha1.h
│   │   ├── sha256.h
│   │   ├── sha512.h
│   │   ├── ssl_cache.h
│   │   ├── ssl_ciphersuites.h
│   │   ├── ssl_cookie.h
│   │   ├── ssl.h
│   │   ├── ssl_internal.h
│   │   ├── ssl_ticket.h
│   │   ├── threading.h
│   │   ├── timing.h
│   │   ├── version.h
│   │   ├── x509_crl.h
│   │   ├── x509_crt.h
│   │   ├── x509_csr.h
│   │   ├── x509.h
│   │   └── xtea.h
│   └── psa
│       ├── crypto_accel_driver.h
│       ├── crypto_compat.h
│       ├── crypto_config.h
│       ├── crypto_driver_common.h
│       ├── crypto_entropy_driver.h
│       ├── crypto_extra.h
│       ├── crypto.h
│       ├── crypto_platform.h
│       ├── crypto_se_driver.h
│       ├── crypto_sizes.h
│       ├── crypto_struct.h
│       ├── crypto_types.h
│       └── crypto_values.h
└── lib
    ├── libmbedcrypto.a
    ├── libmbedtls.a
    └── libmbedx509.a

4 directories, 96 files