Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Can I crosscompile ARM? #1606

Closed
una801 opened this issue Mar 26, 2021 · 8 comments
Closed

How Can I crosscompile ARM? #1606

una801 opened this issue Mar 26, 2021 · 8 comments

Comments

@una801
Copy link

una801 commented Mar 26, 2021

Crosscompile via arm-linux-gnueabi-gcc must be performed to place sdk in the device. I don't know how to cross-compile the certificate and Cmake and make.
How do I cross compile with gnueabi?

@muneebahmed10
Copy link
Contributor

Hi @una801,

The libraries that are part of the C SDK are able to be compiled by any ISO C 89 compiler. However, the demos and platform implementations in this repository are specific to POSIX, so may not build on systems that are not (mostly) POSIX-compliant.

To build an application for another platform, the demos in this repository may be used as a reference, but POSIX-specific calls will have to be replaced with those for your system. If you use CMake to build your application, some parts of the existing CMakeLists.txt files would have to be rewritten if not on POSIX. Or, you may start from scratch, and use each library's existing filepaths .cmake file (e.g. from coreMQTT) to gather the header and source files for each library.

Let us know if you have any further questions.

@una801
Copy link
Author

una801 commented Mar 27, 2021

Thank you for your answer.
It's a bit difficult to talk about, so if you're a POSIX-compatible device, specify the path to cmake (e.g., export CC = arm-linux-gnueabi-gcc).
Are you saying that if you run cmake and make it successful, you can cross compile?

@una801
Copy link
Author

una801 commented Mar 27, 2021

export | grep "arm"
declare -x AR="arm-linux-gnueabi-ar"
declare -x CC="arm-linux-gnueabi-gcc"
declare -x CXX="arm-linux-gnueabi-g++"
declare -x LD="arm-linux-gnueabi-ld"

`-- The C compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/arm-linux-gnueabi-gcc
-- Check for working C compiler: /usr/bin/arm-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.25.1")
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/standard/backoffAlgorithm/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
Using values in demo_config.h to define the following macros for mqtt_demo_basic_tls:
CLIENT_IDENTIFIER
BROKER_PORT
Found the following definitions for mqtt_demo_basic_tls: CLIENT_IDENTIFIER, BROKER_PORT
WARNING: mqtt_demo_basic_tls missing definitions for macros: ROOT_CA_CERT_PATH, BROKER_ENDPOINT
To run mqtt_demo_basic_tls, define required macros in mqtt_demo_basic_tls/demo_config.h.

WARNING: mqtt_demo_mutual_auth missing definitions for macros: AWS_IOT_ENDPOINT, ROOT_CA_CERT_PATH, CLIENT_CERT_PATH, CLIENT_PRIVATE_KEY_PATH, CLIENT_IDENTIFIER
To run mqtt_demo_mutual_auth, define required macros in mqtt_demo_mutual_auth/demo_config.h.

Using values in demo_config.h to define the following macros for mqtt_demo_plaintext:
BROKER_PORT
CLIENT_IDENTIFIER
Found the following definitions for mqtt_demo_plaintext: BROKER_PORT, CLIENT_IDENTIFIER
WARNING: mqtt_demo_plaintext missing definitions for macros: BROKER_ENDPOINT
To run mqtt_demo_plaintext, define required macros in mqtt_demo_plaintext/demo_config.h.

Using values in demo_config.h to define the following macros for mqtt_demo_serializer:
BROKER_PORT
CLIENT_IDENTIFIER
Found the following definitions for mqtt_demo_serializer: BROKER_PORT, CLIENT_IDENTIFIER
WARNING: mqtt_demo_serializer missing definitions for macros: BROKER_ENDPOINT
To run mqtt_demo_serializer, define required macros in mqtt_demo_serializer/demo_config.h.

Using values in demo_config.h to define the following macros for mqtt_demo_subscription_manager:
BROKER_PORT
CLIENT_IDENTIFIER
Found the following definitions for mqtt_demo_subscription_manager: BROKER_PORT, CLIENT_IDENTIFIER
WARNING: mqtt_demo_subscription_manager missing definitions for macros: ROOT_CA_CERT_PATH, BROKER_ENDPOINT
To run mqtt_demo_subscription_manager, define required macros in mqtt_demo_subscription_manager/demo_config.h.

CMake Warning at demos/CMakeLists.txt:25 (message):
rt library could not be found. Demos that use it will be excluded from the
default target.

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
http_demo_s3_download_multithreaded

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
ota_demo_core_http

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
ota_demo_core_mqtt

Downloading the Amazon Root CA certificate...
Downloading the Baltimore Cybertrust Root CA certificate...
-- Configuring incomplete, errors occurred!
See also "/home/youna/aws-iot-device-sdk-embedded-c/build/CMakeFiles/CMakeOutput.log".
See also "/home/youna/aws-iot-device-sdk-embedded-c/build/CMakeFiles/CMakeError.log".
`


it appears error like this..how Can I cross compile this sdk?...

@muneebahmed10
Copy link
Contributor

Hi @una801,

Those errors are from CMake being unable to find librt, which is used for the multithreaded http download demo and the OTA demos. The other demo targets are still able to be built in such a situation.

The demos in this repository are all POSIX or Linux-specific, and though we have compiled for both x64 and ARM, we have not tried cross compiling from different architectures, so I can only provide some recommendations how to proceed with cross compiling. If the target system is also POSIX-compliant, then you may be able to use the existing CMake files without having to make many changes. According to CMake's documentation, you need to manually set CMAKE_SYSTEM_NAME so that the CMAKE_CROSSCOMPILING flag is set. Additionally, you need to make sure that ARM versions of any static libraries used are present in your toolchain. The following line from your output

-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")

would likely lead to an error when trying to build, as the shared object looks to be compiled for x64 and not ARM. You would need to make sure an ARM-compatible version is present on your machine and able to be found by CMake, or link it dynamically.

@una801
Copy link
Author

una801 commented Mar 31, 2021

`cmake .. -DOPENSSL_INCLUDE_DIR=/home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr/include/openssl -DOPENSSL_LIBRARIES=/home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr/lib -DOPENSSL_CRYPTO_LIBRARY=/home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr/lib/libcrypt.so -DOPENSSL_SSL_LIBRARY=/home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr/lib/libssl.so -DBUILD_SHARED_LIBS=ON -DOPENSSL_ROOT_DIR=/home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi
-- The C compiler identification is GNU 4.9.2
-- Check for working C compiler: /home/youna/tm2sdk/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc
-- Check for working C compiler: /home/youna/tm2sdk/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found Git: /usr/bin/git (found version "2.25.1")
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-defender-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/device-shadow-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/jobs-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/aws/ota-for-aws-iot-embedded-sdk/source/dependency/coreJSON/'
Skipping submodule '../../../libraries/standard/backoffAlgorithm/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreHTTP/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreJSON/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../libraries/standard/coreMQTT/'
Skipping submodule '../../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
Skipping submodule '../../../libraries/standard/corePKCS11/'
-- Found OpenSSL: /home/youna/tm2sdk/sysroots/armv7a-vfp-neon-oe-linux-gnueabi/usr/lib/libcrypt.so
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
Using values in demo_config.h to define the following macros for defender_demo:
ROOT_CA_CERT_PATH
THING_NAME
CLIENT_IDENTIFIER
OS_NAME
OS_VERSION
HARDWARE_PLATFORM_NAME
Found the following definitions for defender_demo: ROOT_CA_CERT_PATH, THING_NAME, CLIENT_IDENTIFIER, OS_NAME, OS_VERSION, HARDWARE_PLATFORM_NAME
WARNING: defender_demo missing definitions for macros: AWS_IOT_ENDPOINT, CLIENT_CERT_PATH, CLIENT_PRIVATE_KEY_PATH, CLIENT_USERNAME, CLIENT_PASSWORD
To run defender_demo, define required macros in defender_demo/demo_config.h.

Using values in demo_config.h to define the following macros for mqtt_demo_mutual_auth:
AWS_IOT_ENDPOINT
ROOT_CA_CERT_PATH
CLIENT_CERT_PATH
CLIENT_PRIVATE_KEY_PATH
CLIENT_IDENTIFIER
Found the following definitions for mqtt_demo_mutual_auth: AWS_IOT_ENDPOINT, ROOT_CA_CERT_PATH, CLIENT_CERT_PATH, CLIENT_PRIVATE_KEY_PATH, CLIENT_IDENTIFIER
All required definitions for mqtt_demo_mutual_auth were found - Adding to default target.

CMake Warning at demos/CMakeLists.txt:25 (message):
rt library could not be found. Demos that use it will be excluded from the
default target.

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
http_demo_s3_download_multithreaded

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
ota_demo_core_http

CMake Error at demos/CMakeLists.txt:27 (set_target_properties):
set_target_properties Can not find target to add properties to:
ota_demo_core_mqtt

Downloading the Amazon Root CA certificate...
Downloading the Baltimore Cybertrust Root CA certificate...
-- Configuring incomplete, errors occurred!
See also "/home/youna/aws-iot-device-sdk-embedded-c/a/CMakeFiles/CMakeOutput.log".
See also "/home/youna/aws-iot-device-sdk-embedded-c/a/CMakeFiles/CMakeError.log".
`
Is there an error for the same reason that this error occurs even if the openssl library is changed for the same reason?
Cmake is not possible.....

@vikivivi
Copy link

vikivivi commented Apr 1, 2021

-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed

This message is quite common, normally it is OK. I seen it in my system when building for PC as well cross-compile for Raspberry Pi.

rt library could not be found. Demos that use it will be excluded from the
default target.

You need to check why your ARM target sysroot filesystem does not contain librt.
A search on my Raspberry Pi target sysroot filesystem do have librt and it should belong to libc6-dev package.

host$ find ./ -name "librt*"
./usr/lib/arm-linux-gnueabihf/librt.a
./usr/lib/arm-linux-gnueabihf/librt.so
./lib/arm-linux-gnueabihf/librt-2.28.so
./lib/arm-linux-gnueabihf/librt.so.1
raspberrypi$ dpkg -S /usr/lib/arm-linux-gnueabihf/librt.a
libc6-dev:armhf: /usr/lib/arm-linux-gnueabihf/librt.a

raspberrypi$ dpkg -S /usr/lib/arm-linux-gnueabihf/librt.so
libc6-dev:armhf: /usr/lib/arm-linux-gnueabihf/librt.so

If you can identify which demo application is causing the cmake failure, you can temporary disable it.
For my case, when I try to cmake cross-compiling for Raspberry Pi, cmake will failed for demo jobs_demo_mosquitto.
For quick build, I just disabled jobs_demo_mosquitto. To resolve it, I need to install libmosquitto-dev, libmosquitto1 on my Raspberry Pi target sysroot filesystem. The default demo mqtt_demo_mutual_auth cross-compile OK.

host$ mv demos/jobs/jobs_demo_mosquitto/CMakeLists.txt demos/jobs/jobs_demo_mosquitto/CMakeLists.txt.disabled

You might want to use -DCMAKE_TOOLCHAIN_FILE=path/to/file option for cmake when cross compilation.
https://cmake.org/cmake/help/v3.2/manual/cmake-toolchains.7.html#cross-compiling-for-linux

@una801
Copy link
Author

una801 commented Apr 2, 2021

Thank you.
As you said, I moved the librt file from the current openssl library path to /lib and it was compiled without error!

@archigup
Copy link
Member

archigup commented Apr 5, 2021

Hi, as it seems this issue has been resolved, I am closing this issue. If you have further questions on this topic, feel free to open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants