安裝32位工具鏈。

如果您編譯SDK是在一臺安裝了32位Linux 的機器上,那么參考“目標系統為64為Linux”文檔,即可得到32位的庫和例程。

如果您是在安裝了64位Ubuntu16.04的機器上,需要編譯出32位的庫,請按照下文操作

sudo apt-get install -y libc6:i386 libstdC++6:i386 gcc:i386
        

修改平臺配置文件

vim src/board/config.ubuntu.x86
        

增加如下一行

CONFIG_ENV_CFLAGS   += -m32
        

比如:

cat src/board/config.ubuntu.x86

CONFIG_ENV_CFLAGS   += \
    -Os -Wall \
    -g3 --coverage \
    -D_PLATFORM_IS_LINUX_ \
    -D__UBUNTU_SDK_DEMO__ \

...
...
CONFIG_ENV_LDFLAGS  += -lpthread -lrt

CONFIG_ENV_LDFLAGS  += -m32
OVERRIDE_STRIP      := strip
        

選擇平臺配置

make reconfig
SELECT A CONFIGURATION:

1) config.macos.make    3) config.ubuntu.x86
2) config.rhino.make    4) config.win7.mingw32
#? 3
        

編譯

make
        

獲取二進制庫

cd output/release/lib
ls
        

其中有三個主要產物,它們都是32位架構的

產物文件名 說明
libiot_hal.a HAL接口層的參考實現,提供了HAL_XXX()接口
libiot_sdk.a SDK的主庫,提供了IOT_XXX接口和linkkit_xxx()接口
libiot_tls.a 裁剪過的mbedtls,提供了mbedtls_xxx()接口,支撐libiot_hal.a

獲取可執行程序

cd output/release/bin
ls
        

其中有兩個主要產物,它們都是32位架構的

產物文件名 說明
linkkit-example-solo 高級版(舊版API)的例程,可演示linkkit_xxx()接口的使用
mqtt-example 基礎版的例程,可演示IOT_XXX()接口的使用

可以用如下方式驗證,注意file命令的輸出中,已經顯示程序都是32位的了(ELF 32-bit LSB executable)。

file output/release/bin/*

output/release/bin/linkkit-example-countdown: ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/linkkit-example-sched:     ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/linkkit-example-solo:      ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/linkkit_tsl_convert:       ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/mqtt-example:              ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/mqtt-example-multithread:  ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/mqtt-example-rrpc:         ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/ota-example-mqtt:          ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/sdk-testsuites:            ELF 32-bit LSB executable, Intel 80386, ... stripped
output/release/bin/uota_app-example:          ELF 32-bit LSB executable, Intel 80386, ... stripped
        

使用cmake方式編譯

修改CMakeLists.txt 文件

在默認的文件中修改CFLAGS,加入-m32

SET (CMAKE\_C\_FLAGS " -Iexamples -Os -Wall")
            

改成

SET (CMAKE\_C\_FLAGS " -Iexamples -Os -Wall -m32")
            

從CMakeLists.txt構建makefile

mkdir ooo
cd ooo
cmake ..
            

編譯

make -j32
            

產物

~/srcs/iotx-sdk-c/ooo\$ ls
bin  CMakeCache.txt  CMakeFiles  cmake\_install.cmake  examples  lib  Makefile  src  tests
            

可執行程序在bin/ 目錄下:

ls bin/

linkkit-example-countdown  linkkit-example-sched  linkkit-example-solo  linkkit\_tsl\_convert
mqtt-example  mqtt\_example\_multithread  mqtt\_example\_rrpc  ota-example-mqtt  uota\_app-example
            

可以用如下方式驗證,注意file命令的輸出中,已經顯示程序都是32位的了(ELF 32-bit LSB executable)。

file ooo/bin/\*

ooo/bin/linkkit-example-countdown: ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/linkkit-example-sched:     ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/linkkit-example-solo:      ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/linkkit\_tsl\_convert:       ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/mqtt-example:              ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/mqtt-example-multithread:  ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/mqtt-example-rrpc:         ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/ota-example-mqtt:          ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/sdk-testsuites:            ELF 32-bit LSB executable, Intel 80386, ... stripped
ooo/bin/uota\_app-example:          ELF 32-bit LSB executable, Intel 80386, ... stripped
            

二進制庫在lib/ 目錄下:

ls lib/

libiot\_hal.so  libiot\_sdk.so  libiot\_tls.so