安装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