Building the MQTT client for C libraries

Follow these steps to build the MQTT client for C libraries. The topic includes the compile and link switches for a number of platforms, and examples of building the libraries on iOS and Windows.

Before you begin

  1. Build the C client library only when necessary. Link the pre-built client libraries in the (Software Development Kit) SDK in the SDK\clients\c subdirectory if one matches your target platform.
  2. Configure an MQTT server to test the library you build with the MQTT client sample C app. See Getting started with MQTT servers. Verify the server configuration by running one of the MQTT client sample apps.
  3. If you are building a secure version of the C library, which supports (Secure Sockets Layer) SSL, you must also build the OpenSSL library. See Building the OpenSSL package.
    Important: Download and redistribution of the OpenSSL package is subject to stringent import and export regulation, and open source licensing conditions. Take careful note of the restrictions and warnings before you decide whether to download the package.

About this task

Follow the instructions in Building the OpenSSL package to download and build the OpenSSL library. You must build the OpenSSL to build a secure version of the MQTT client for C library. You do not require OpenSSL to build an unsecured version of the MQTT library. The steps include examples of building the library for iOS and Windows.

Build the MQTT client for C library by downloading C development library tools, and the MQTT software development toolkit (SDK) onto your build platform. Write a makefile to build the library for your target platform, incorporating the options that are documented in MQTT build options for different platforms. Platform-specific steps to build and run a makefile are given here:

Procedure

  1. Install a C development environment on the platform on which you are building.
    The makefiles in the examples in this topic target the following tools:
    • iOSFor iOS, on Apple Mac with OS X 10.8.2 with the iOS development tools from Xcode.
    • LinuxFor Linux®, gcc version 4.4.6 from Red Hat® Enterprise Linux version 6.2.

      The minimum supported level of the glibc C library is 2.12, and of the Linux kernel is 2.6.32.

    • WindowsFor Microsoft Windows, Visual Studio version 10.0.
  2. Download the Mobile Messaging and M2M Client Pack and install the MQTT SDK.
    There is no installation program, you just expand the downloaded file.
    1. Download the Mobile Messaging and M2M Client Pack.
    2. Create a folder where you are going to install the SDK.

      You might want to name the folder MQTT. The path to this folder is referred to here as sdkroot.

    3. Expand the compressed Mobile Messaging and M2M Client Pack file contents into sdkroot. The expansion creates a directory tree that starts at sdkroot\SDK.
  3. Expand the source code for the MQTT client for C libraries.

    The source code compressed file is sdkroot\SDK\clients\c\source.zip.

  4. Optional: Build OpenSSL.
  5. Build the MQTT client for C libraries.

    The commands and options to build the libraries are listed in MQTT build options for different platforms.

    Follow the steps in the following examples to write a makefile to build the MQTT client for C libraries for your target platform.

MQTT build options for different platforms

The following table lists the compiler and build options to build the MQTT client for C libraries on various platforms.

Table 1. MQTT build options for different platforms
Platform Compiler Compiler Options Linker Options Extra Options
AIX® gcc
-fPIC -Os -Wall -DREVERSED
-I MQTTCLIENT_DIR
-Wl,-G
 
Linux s390x
-shared -Wl,-soname, libmqttv3c.so
-m64
Linux x86-64
-fPIC -Os -Wall -I MQTTCLIENT_DIR
Linux x86-32
-m32
Linux ARM (glibc) arm-linux-gcc  
Linux ARM (uclibc)
arm-unknown-linux
-uclibcgnueabi-gcc
Windows 32-bit cl
/D "WIN32" /D "_UNICODE" /D "UNICODE"
/D "_CRT_SECURE_NO_WARNINGS"
/nologo /c /O2 /W3 /Fd /MD /TC
/nologo /machine:x86 /manifest
kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib
uuid.lib odbc32.lib odbccp32.lib
ws2_32.lib /implib:mqttv3c.lib)
/pdb:mqttv3c.pdb) /map:mqttv3c.map)
 
iOS ARMv7 gcc -arch armv7
-DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  -DOPENSSL
-Os -Wall -fomit-frame-pointer

-isysroot /Applications/Xcode.app/\
Contents/Developer/Platforms/\
iPhoneOS.platform/Developer/SDKs/\
iPhoneOS6.0.sdk
-L/Applications/Xcode.app/
Contents/Developer/Platforms/
iPhoneOS.platform/Developer/SDKs/
iPhoneOS6.0.sdk/usr/lib/system
 
iOS ARMv7s gcc -arch armv7s
iOS ARMi386 gcc -arch i386
-DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  -DOPENSSL
-Os -Wall -fomit-frame-pointer

-isysroot /Applications/Xcode.app/\
Contents/Developer/Platforms/\
iPhoneSimulator.platform/
Developer/SDKs/iPhoneSimulator6.0.sdk
-L/Applications/Xcode.app/
Contents/Developer/Platforms/
iPhoneSimulator.platform/Developer/SDKs/
iPhoneSimulator6.0.sdk/usr/lib/system
 
iOS

Building the MQTT client libraries for C on an Apple Mac for use with iOS devices

Follow these steps to write a makefile to build the MQTT client libraries for C on an Apple Mac, for subsequent use with iOS devices.

Before you begin

  1. Install build tools, develop, and run the makefile on Apple Mac with OS X 10.8.2, or later.
  2. Install the command-line tools for Xcode, which include the make program. Download the command-line tools from Xcode.

About this task

Create a makefile that builds MQTT client libraries for C for iPhone or iPad running an ARMv7 or ARMv7s processor, and the iPhone simulator that runs on an i386-64 bit processor. See List of iOS devices.

Tip: MQTTios.mak makefile listing lists the complete makefile.
  1. Copy and paste the listing into a file.
  2. Convert the leading character of each line that follows a target to a tab; see step 8.
  3. Run it with the command listed in step 9 of the procedure.

Procedure

  1. Download and install the iOS development tools.
    1. Log on with a user ID that has administrative privileges.
    2. Check your Apple Mac is at version 10.8.2 or later.
    3. Go to the website Xcode to download Xcode from the Mac app store.
    4. Install Xcode, the command-line environment, and the simulator.
    If the Mac app store offers multiple versions of the simulator, choose the version that is compatible with the level of iOS you are targeting for your app.
  2. Create the makefile MQTTios.mak
    Add a prolog:
    # Build output is produced in the current directory.
    # MQTTCLIENT_DIR must point to the base directory containing the MQTT client source code. 
    # Default MQTTCLIENT_DIR is the current directory 
    # Default TOOL_DIR is /Applications/Xcode.app/Contents/Developer/Platforms 
    # Default OPENSSL_DIR is sdkroot/openssl, relative to sdkroot/sdk/clients/c/mqttv3c/src 
    # OPENSSL_DIR must point to the base directory containing the OpenSSL build.  
    # Example:  make -f MQTTios.mak MQTTCLIENT_DIR=sdkroot/sdk/clients/c/mqttv3c/src all
  3. Set the location of the MQTT source code.

    Run the makefile in the same directory as the MQTT source files, or set the MQTTCLIENT_DIR command-line parameter:

    make -f makefile MQTTCLIENT_DIR=sdkroot/SDK/clients/c/mqttv3c/src
    Add the following lines to the makefile:
    ifndef MQTTCLIENT_DIR
      MQTTCLIENT_DIR = ${CURDIR}
    endif
    VPATH = ${MQTTCLIENT_DIR} 
    The example sets VPATH to the directory where make searches for source files that are not explicitly identified; for example all the header files that are required in the build.
  4. Optional: Set the location of the OpenSSL libraries.

    This step is required to build the SSL versions of the MQTT client for C libraries.

    Set the default path to the OpenSSL libraries to same directory as you expanded the MQTT SDK. Otherwise, set OPENSSL_DIR as a command-line parameter.

    ifndef OPENSSL_DIR
      OPENSSL_DIR = ${MQTTCLIENT_DIR}/../../../../../openssl-1.0.1c
    endif
    Tip: OpenSSL is the OpenSSL directory that contains all the OpenSSL subdirectories. You might have to move the directory tree from where you expanded it, because it contains unnecessary empty parent directories.
  5. Set the development tools directories.

    If you installed Xcode in a different location, set TOOL_DIR in the command line.

    ifndef TOOL_DIR
       TOOL_DIR = /Applications/Xcode.app/Contents/Developer/Platforms endif 
    IPHONE_SDK = iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk 
    IPHONESIM_SDK = iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk 
    SDK_ARM = ${TOOL_DIR}/${IPHONE_SDK} 
    SDK_i386 = ${TOOL_DIR}/${IPHONESIM_SDK}
  6. Select all the source files that are required to build each MQTT library. Also, set the name and location of the MQTT library to build.

    Add the following line to the makefile to list all the MQTT source files:

    ALL_SOURCE_FILES = ${wildcard ${MQTTCLIENT_DIR}/*.c}

    The source files depend on whether you are building a synchronous or asynchronous library, and whether the library includes SSL or not.

    Add one or more of these lines, which depend on the targets to build. The shared libraries are created in the darwin_x86_64 directory.

    • Synchronous, unsecured:
      MQTTLIB = mqttv3c 
      SOURCE_FILES = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}} 
      MQTTLIB_DARWIN = darwin_x86_64/lib${MQTTLIB}.a
    • Synchronous, secured:
      MQTTLIB_S = mqttv3cs
      SOURCE_FILES_S = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c, ${ALL_SOURCE_FILES}}
      MQTTLIB_DARWIN_S = darwin_x86_64/lib${MQTTLIB_S}.a
    • Asynchronous, unsecured:
      MQTTLIB_A = mqttv3a
      SOURCE_FILES_A = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
      MQTTLIB_DARWIN_A = darwin_x86_64/lib${MQTTLIB_A}.a
    • Asynchronous secured:
      MQTTLIB_AS = mqttv3as
      SOURCE_FILES_AS = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c, ${ALL_SOURCE_FILES}}
      MQTTLIB_DARWIN_AS = darwin_x86_64/lib${MQTTLIB_AS}.a
  7. Define the compiler, and compiler options.

    See the options for different platforms that are shown in MQTT build options for different platforms.

    1. Set Gnu project C and C++ (gcc) as the compiler.

      Select three cross-compilers to build the library for different devices and the iPhone simulator:

      CC = iPhoneOS.platform/Developer/usr/bin/gcc
      CC_armv7 = ${TOOL_DIR}/${CC} -arch armv7
      CC_armv7s = ${TOOL_DIR}/${CC} -arch armv7s
      CC_i386 = ${TOOL_DIR}/${CC} -arch i386
    2. Add the compiler options.
      CCFLAGS = -Os -Wall -fomit-frame-pointer
    3. Add the include paths.
      CCFLAGS_SO_ARM =  ${CCFLAGS} -isysroot ${SDK_ARM} -I${OPENSSL_DIR}/include  -L${SDK_ARM}/usr/lib/system
      CCFLAGS_SO_i386 = ${CCFLAGS} -isysroot ${SDK_i386} -I${OPENSSL_DIR}/include -L${SDK_i386}/usr/lib/system
  8. Define the build targets.
    Tip: Each successive line that defines the implementation of a target must start with a tab character.
    1. Define the all target.

      The all target builds all the libraries.

      all: ${MQTTLIB_DARWIN} ${MQTTLIB_DARWIN_A} ${MQTTLIB_DARWIN_AS} ${MQTTLIB_DARWIN_S}

      By listing it first, it is the default target.

    1. Build the synchronous, unsecured library, libmqttv3c.a.
      ${MQTTLIB_DARWIN}: ${SOURCE_FILES}
          -mkdir darwin_x86_64
          ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_ARM} -o $@.armv7 *.o
          rm *.o
          ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_ARM} -o $@.armv7s *.o
          rm *.o
          ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_i386} -o $@.i386 *.o
          rm *.o
          lipo -create $@.armv7 $@.armv7s $@.i386 -output $@
      The statement rm *.o deletes all the object files that are created for each library. lipo concatenates all three libraries into one file.
    2. Build the asynchronous, unsecured library, libmqttv3a.a.
      ${MQTTLIB_DARWIN_A}: ${SOURCE_FILES_A} 
          -mkdir darwin_x86_64
          ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_ARM} -o $@.armv7 *.o
          rm *.o
          ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_ARM} -o $@.armv7s *.o
          rm *.o
          ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
          libtool -static -syslibroot ${SDK_i386} -o $@.i386 *.o
          rm *.o
          lipo -create $@.armv7 $@.armv7s $@.i386 -output $@
      The statement rm *.o deletes all the object files that are created for each library. lipo concatenates all three libraries into one file.
    3. Build the synchronous, secured library, libmqttv3cs.a.
      ${MQTTLIB_DARWIN_S}: ${SOURCE_FILES_S} 
          -mkdir darwin_x86_64
          ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7 -lssl -lcrypto -o $@.armv7 *.o
          rm *.o
          ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7s -lssl -lcrypto -o $@.armv7s *.o
          rm *.o
          ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/i386 -lssl -lcrypto -o $@.i386 *.o
          rm *.o
          lipo -create $@.armv7 $@.armv7s $@.i386 -output $@
      The statement rm *.o deletes all the object files that are created for each library. lipo concatenates all three libraries into one file.
    4. Build the asynchronous, secured library, libmqttv3as.a.
      ${MQTTLIB_DARWIN_AS}: ${SOURCE_FILES_AS}
          -mkdir darwin_x86_64
          ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7 -lssl -lcrypto -o $@.armv7 *.o
          rm *.o
          ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7s -lssl -lcrypto -o $@.armv7s *.o
          rm *.o
          ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
          libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/i386 -lssl -lcrypto -o $@.i386 *.o
          rm *.o
          lipo -create $@.armv7 $@.armv7s $@.i386 -output $@
      The statement rm *.o deletes all the object files that are created for each library. lipo concatenates all three libraries into one file.
    5. Define the clean target.

      The clean target removes all the files and directories that are generated by the makefile

      .PHONY : clean
      clean: 
          -rm -f *.obj
          -rm -f -r darwin_x86_64 
  9. Run the makefile.
    make -f  MQTTCLIENT_DIR=sdkroot/sdk/clients/c/mqttv3c/src 

Results

The following files are created in the sdkroot/sdk/clients/c/mqttv3c/src/darwin_x86_64 directory.
libmqttv3c.a.armv7
libmqttv3c.a.armv7s
libmqttv3c.a.i386
libmqttv3c.a
libmqttv3a.a.armv7
libmqttv3a.a.armv7s
libmqttv3a.a.i386
libmqttv3a.a
libmqttv3cs.a.armv7
libmqttv3cs.a.armv7s
libmqttv3cs.a.i386
libmqttv3cs.a
libmqttv3as.a.armv7
libmqttv3as.a.armv7s
libmqttv3as.a.i386
libmqttv3as.a

MQTTios.mak makefile listing

# Build output is produced in the current directory.
# MQTTCLIENT_DIR must point to the base directory containing the MQTT client source code. 
# Default MQTTCLIENT_DIR is the current directory 
# Default TOOL_DIR is /Applications/Xcode.app/Contents/Developer/Platforms 
# Default OPENSSL_DIR is sdkroot/openssl, relative to sdkroot/sdk/clients/c/mqttv3c/src 
# OPENSSL_DIR must point to the base directory containing the OpenSSL build.  
# Example:  make -f MQTTios.mak MQTTCLIENT_DIR=sdkroot/sdk/clients/c/mqttv3c/src all

ifndef MQTTCLIENT_DIR
  MQTTCLIENT_DIR = ${CURDIR}
endif
VPATH = ${MQTTCLIENT_DIR} 
ifndef OPENSSL_DIR
  OPENSSL_DIR = ${MQTTCLIENT_DIR}/../../../../../openssl-1.0.1c
endif
ALL_SOURCE_FILES = ${wildcard ${MQTTCLIENT_DIR}/*.c}
ifndef TOOL_DIR
   TOOL_DIR = /Applications/Xcode.app/Contents/Developer/Platforms endif 
IPHONE_SDK = iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk 
IPHONESIM_SDK = iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk 
SDK_ARM = ${TOOL_DIR}/${IPHONE_SDK} 
SDK_i386 = ${TOOL_DIR}/${IPHONESIM_SDK}

MQTTLIB = mqttv3c 
SOURCE_FILES = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}} 
MQTTLIB_DARWIN = darwin_x86_64/lib${MQTTLIB}.a
MQTTLIB_S = mqttv3cs
SOURCE_FILES_S = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c, ${ALL_SOURCE_FILES}}
MQTTLIB_DARWIN_S = darwin_x86_64/lib${MQTTLIB_S}.a
MQTTLIB_A = mqttv3a
SOURCE_FILES_A = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
MQTTLIB_DARWIN_A = darwin_x86_64/lib${MQTTLIB_A}.a
MQTTLIB_AS = mqttv3as
SOURCE_FILES_AS = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c, ${ALL_SOURCE_FILES}}
MQTTLIB_DARWIN_AS = darwin_x86_64/lib${MQTTLIB_AS}.a

# compiler
CC = iPhoneOS.platform/Developer/usr/bin/gcc
CC_armv7 = ${TOOL_DIR}/${CC} -arch armv7
CC_armv7s = ${TOOL_DIR}/${CC} -arch armv7s
CC_i386 = ${TOOL_DIR}/${CC} -arch i386
CCFLAGS = -Os -Wall -fomit-frame-pointer
CCFLAGS_SO_ARM =  ${CCFLAGS} -isysroot ${SDK_ARM} -I${OPENSSL_DIR}/include  -L${SDK_ARM}/usr/lib/system
CCFLAGS_SO_i386 = ${CCFLAGS} -isysroot ${SDK_i386} -I${OPENSSL_DIR}/include -L${SDK_i386}/usr/lib/system

# targets
all: ${MQTTLIB_DARWIN} ${MQTTLIB_DARWIN_A} ${MQTTLIB_DARWIN_AS} ${MQTTLIB_DARWIN_S}

${MQTTLIB_DARWIN}: ${SOURCE_FILES}
    -mkdir darwin_x86_64
    ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_ARM} -o $@.armv7 *.o
    rm *.o
    ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_ARM} -o $@.armv7s *.o
    rm *.o
    ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES} -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_i386} -o $@.i386 *.o
    rm *.o
    lipo -create $@.armv7 $@.armv7s $@.i386 -output $@

${MQTTLIB_DARWIN_A}: ${SOURCE_FILES_A} 
    -mkdir darwin_x86_64
    ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_ARM} -o $@.armv7 *.o
    rm *.o
    ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_ARM} -o $@.armv7s *.o
    rm *.o
    ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_A} -DMQTT_ASYNC -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE 
    libtool -static -syslibroot ${SDK_i386} -o $@.i386 *.o
    rm *.o
    lipo -create $@.armv7 $@.armv7s $@.i386 -output $@    

${MQTTLIB_DARWIN_S}: ${SOURCE_FILES_S} 
    -mkdir darwin_x86_64
    ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7 -lssl -lcrypto -o $@.armv7 *.o
    rm *.o
    ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7s -lssl -lcrypto -o $@.armv7s *.o
    rm *.o
    ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_S} -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/i386 -lssl -lcrypto -o $@.i386 *.o
    rm *.o
    lipo -create $@.armv7 $@.armv7s $@.i386 -output $@

${MQTTLIB_DARWIN_AS}: ${SOURCE_FILES_AS}
    -mkdir darwin_x86_64
    ${CC_armv7} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7 -lssl -lcrypto -o $@.armv7 *.o
    rm *.o
    ${CC_armv7s} ${CCFLAGS_SO_ARM} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/armv7s -lssl -lcrypto -o $@.armv7s *.o
    rm *.o
    ${CC_i386} ${CCFLAGS_SO_i386} -c ${SOURCE_FILES_AS} -DMQTT_ASYNC -DOPENSSL -DUSE_NAMED_SEMAPHORES -DNOSIGPIPE  
    libtool -static -syslibroot ${SDK_ARM} -L${OPENSSL_DIR}/i386 -lssl -lcrypto -o $@.i386 *.o
    rm *.o
    lipo -create $@.armv7 $@.armv7s $@.i386 -output $@

.PHONY : clean
clean: 
    -rm -f *.obj
    -rm -f -r darwin_x86_64 
Windows

Building the MQTT libraries on Windows

Follow these steps to write a makefile to build the MQTT client libraries for C on Windows.

Before you begin

  1. If necessary, install a version of Make on your build workstation that is compatible with makefiles written for Gnu make; otherwise download Gnu make and build it. See Gnu Make. The website, Make for Windows, provides an installable version of Make for Windows.
  2. You also require Linux commands for Windows to use the clean target in the makefile example. You can obtain Linux commands for Windows from websites such as Cygwin.

About this task

Create a makefile that builds MQTT client libraries for C for Windows 32 bit.

Tip: MQTTwin.mak makefile listing lists the complete makefile.
  1. Copy and paste the listing into a file.
  2. Convert the leading character of each line that follows a target to a tab; see step 7.
  3. Run it with the command listed in step 9 of the procedure.

Procedure

  1. Create the makefile MQTTwin.mak
    Add a prolog:
    # Build output is produced in the current directory.
    # MQTTCLIENT_DIR must point to the base directory containing the MQTT client source code.
    # Default MQTTCLIENT_DIR is the current directory
    # Default OPENSSL_DIR is sdkroot\openSSL, relative to sdkroot\sdk\clients\c\mqttv3c\src
    # OPENSSL_DIR must point to the base directory containing the OpenSSL build. 
    # Example:  make -f MQTTwin.mak MQTTCLIENT_DIR=sdkroot/sdk/clients/c/mqttv3c/src
    # Set the build environment, for example:
    #    %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
    #    set path=%path%;C:\Program Files\GnuWin32\bin;C:\cygwin\bin
  2. Set the location of the MQTT source code.

    Run the makefile in the same directory as the MQTT source files, or set the MQTTCLIENT_DIR command-line parameter:

    make -f makefile MQTTCLIENT_DIR=sdkroot/SDK/clients/c/mqttv3c/src
    Add the following lines to the makefile:
    ifndef MQTTCLIENT_DIR
      MQTTCLIENT_DIR = ${CURDIR}
    endif
    VPATH = ${MQTTCLIENT_DIR} 
    The example sets VPATH to the directory where make searches for source files that are not explicitly identified; for example all the header files that are required in the build.
  3. Optional: Set the location of the OpenSSL libraries.

    This step is required to build the SSL versions of the MQTT client for C libraries.

    Set the default path to the OpenSSL libraries to same directory as you expanded the MQTT SDK. Otherwise, set OPENSSL_DIR as a command-line parameter.

    ifndef OPENSSL_DIR
      OPENSSL_DIR = ${MQTTCLIENT_DIR}/../../../../../openssl-1.0.1c
    endif
    Tip: OpenSSL is the OpenSSL directory that contains all the OpenSSL subdirectories. You might have to move the directory tree from where you expanded it, because it contains unnecessary empty parent directories.
  4. Select all the source files that are required to build each MQTT library. Also, set the name and location of the MQTT library to build.

    Add the following line to the makefile to list all the MQTT source files:

    ALL_SOURCE_FILES = ${wildcard ${MQTTCLIENT_DIR}/*.c}

    The source files depend on whether you are building a synchronous or asynchronous library, and whether the library includes SSL or not.

    Add one or more of these lines, which depend on the targets to build. The shared libraries and manifests are created in the windows_ia32 directory.

    • Synchronous, unsecured:
      MQTTLIB = mqttv3c
      MQTTDLL = windows_ia32/${MQTTLIB}.dll
      SOURCE_FILES = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
      MANIFEST = mt -manifest ${MQTTDLL}.manifest -outputresource:${MQTTDLL}\;2
    • Synchronous, secured:
      MQTTLIB_S = mqttv3cs
      MQTTDLL_S  = windows_ia32/${MQTTLIB_S}.dll
      SOURCE_FILES_S = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c, ${ALL_SOURCE_FILES}}
      MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2
    • Asynchronous, unsecured:
      MQTTLIB_A = mqttv3a
      MQTTDLL_A  = windows_ia32/${MQTTLIB_A}.dll
      SOURCE_FILES_A = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
      MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2
    • Asynchronous secured:
      MQTTLIB_AS = mqttv3as
      MQTTDLL_AS  = windows_ia32/${MQTTLIB_AS}.dll
      SOURCE_FILES_AS = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c, ${ALL_SOURCE_FILES}}
      MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2
  5. Define the compiler, and compiler options.

    See the options for different platforms that are shown in MQTT build options for different platforms.

    1. Set Microsoft Visual C++ as the compiler.
      CC = cl
    2. Add the pre-processor options.
      CPPFLAGS = /D "WIN32" /D "_UNICODE" /D "UNICODE" /D "_CRT_SECURE_NO_WARNINGS"
    3. Add the compiler options.
      CFLAGS = /nologo /c /O2 /W3 /Fd /MD /TC
    4. Add the include paths.
      INC =  /I ${MQTTCLIENT_DIR} /I ${MQTTCLIENT_DIR}/..
    5. Optional: Add a pre-processor option, if you are building a secure library.
      CPPFLAGS_S = ${CPPFLAGS} /D "OPENSSL"
    6. Optional: Add the OpenSSL header files, if you are building a secure library.
      INC_S = ${INC} /I ${OPENSSL_DIR}/inc32/
      Tip: The header files are in ${OPENSSL_DIR}/inc32/openssl, but the ssl.h file is included with openssl/ssl.h.
  6. Set the linker, and linker options.
    1. Set Microsoft Visual C++ as the linker.
      LD = link
    2. Add the linker options.
      LINKFLAGS = /nologo /machine:x86 /manifest /dll
    3. Add the library paths.
      WINLIBS = kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
                advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
                odbc32.lib odbccp32.lib ws2_32.lib
    4. Add the intermediate output files.
      IMP = /implib:${@:.dll=.lib}
      LIBPDB = /pdb:${@:.dll=.pdb}
      LIBMAP = /map:${@:.dll=.map}
    5. Optional: Add the OpenSSL libraries, if you are building a secure library.
      WINLIBS_S = ${WINLIBS} crypt32.lib ssleay32.lib libeay32.lib
    6. Optional: Add the OpenSSL library path, if you are building a secure library.
      LIBPATH_S = /LIBPATH:${OPENSSL_DIR}/lib
  7. Define the four build targets.
    1. Define the all target.
      Tip: Each successive line that defines the implementation of a target must start with a tab character.

      The all target builds all the libraries.

      all: ${MQTTDLL} ${MQTTDLL_A} ${MQTTDLL_AS} ${MQTTDLL_S}
    2. Build the synchronous, unsecured library, mqttv3c.dll.
      ${MQTTDLL}: ${SOURCE_FILES}  
          -mkdir windows_ia32
          -rm ${CURDIR}/MQTTAsync.obj
          ${CC} ${CPPFLAGS} ${CFLAGS} ${INC} /Fo ${SOURCE_FILES}
          ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS} *.obj /out:${MQTTDLL}
          ${MANIFEST}

      The statement -rm ${CURDIR}/MQTTAsync.obj deletes any MQTTAsync.obj created for an earlier target. MQTTAsync.obj and MQTTClient.obj are mutually exclusive.

    3. Build the asynchronous, unsecured library, mqttv3a.dll.
      ${MQTTDLL_A}: ${SOURCE_FILES_A}  
          -mkdir windows_ia32
          -rm ${CURDIR}/MQTTClient.obj
          ${CC} ${CPPFLAGS} ${CFLAGS} ${INC} /Fo ${SOURCE_FILES_A}
          ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS} *.obj /out:${MQTTDLL_A}
          ${MANIFEST_A}

      The statement -rm ${CURDIR}/MQTTClient.obj deletes any MQTTClient.obj created for an earlier target. MQTTAsync.obj and MQTTClient.obj are mutually exclusive.

    4. Build the synchronous, secured library, mqttv3cs.dll.
      ${MQTTDLL_S}: ${SOURCE_FILES_S} 
          -mkdir windows_ia32
          -rm ${CURDIR}/MQTTAsync.obj
          ${CC} ${CPPFLAGS_S} ${CFLAGS} ${INC_S} /Fo ${SOURCE_FILES}
          ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS_S} ${LIBPATH_S} *.obj /out:${MQTTDLL_S}
          ${MANIFEST_S}

      The statement -rm ${CURDIR}/MQTTAsync.obj deletes any MQTTAsync.obj created for an earlier target. MQTTAsync.obj and MQTTClient.obj are mutually exclusive.

    5. Build the asynchronous, secured library, mqttv3as.dll.
      ${MQTTDLL_AS}: ${SOURCE_FILES_AS} 
          -rm ${CURDIR}/MQTTClient.obj
          ${CC} ${CPPFLAGS_S} ${CFLAGS} ${INC_S} /Fo ${SOURCE_FILES_AS}
          ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS_S} ${LIBPATH_S} *.obj /out:$(MQTTDLL_AS}
          $(MANIFEST_AS}

      The statement -rm $(CURDIR}/MQTTClient.obj deletes any MQTTClient.obj created for an earlier target. MQTTAsync.obj and MQTTClient.obj are mutually exclusive.

    6. Define the clean target.

      The clean target removes all the files and directories that are generated by the makefile

      .PHONY : clean
      clean: 
          -rm -f *.obj
          -rm -f -r windows_ia32 
  8. Set the Windows path to run the makefile.

    Set the parts in italics to match your installation.

    1. Set the Microsoft Visual Studio environment.
      %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
    2. Set the Path variable to include the make program and the Linux command environment.
      set path=%path%;C:\Program Files\GnuWin32\bin;C:\cygwin\bin
  9. Run the makefile.
    make -f MQTTwin.mak MQTTCLIENT_DIR=sdkroot/SDK/clients/c/mqttv3c/src 
    Tip: The file separator character must be a forward slash, not a backward slash.

Results

The following files are created in the sdkroot\SDK\clients\c\mqttv3c\src\windows_ia32 directory.
mqttv3a.dll
mqttv3a.dll.manifest
mqttv3a.exp
mqttv3a.lib
mqttv3a.map
mqttv3as.dll
mqttv3as.dll.manifest
mqttv3as.exp
mqttv3as.lib
mqttv3as.map
mqttv3c.dll
mqttv3c.dll.manifest
mqttv3c.exp
mqttv3c.lib
mqttv3c.map
mqttv3cs.dll
mqttv3cs.dll.manifest
mqttv3cs.exp
mqttv3cs.lib
mqttv3cs.map

MQTTwin.mak makefile listing

# Build output is produced in the current directory.
# MQTTCLIENT_DIR must point to the base directory containing the MQTT client source code.
# Default MQTTCLIENT_DIR is the current directory
# Default OPENSSL_DIR is sdkroot\openSSL, relative to sdkroot\sdk\clients\c\mqttv3c\src
# OPENSSL_DIR must point to the base directory containing the OpenSSL build. 
# Example:  make -f MQTTwin.mak MQTTCLIENT_DIR=sdkroot/sdk/clients/c/mqttv3c/src
# Set the build environment, for example:
#    %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
#    set path=%path%;C:\Program Files\GnuWin32\bin;C:\cygwin\bin
ifndef MQTTCLIENT_DIR
  MQTTCLIENT_DIR = ${CURDIR}
endif
VPATH = ${MQTTCLIENT_DIR} 
ifndef OPENSSL_DIR
  OPENSSL_DIR = ${MQTTCLIENT_DIR}/../../../../../openssl-1.0.1c
endif

ALL_SOURCE_FILES = ${wildcard ${MQTTCLIENT_DIR}/*.c}

MQTTLIB = mqttv3c
MQTTDLL = windows_ia32/${MQTTLIB}.dll
SOURCE_FILES = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
MANIFEST = mt -manifest ${MQTTDLL}.manifest -outputresource:${MQTTDLL}\;2
MQTTLIB_S = mqttv3cs
MQTTDLL_S  = windows_ia32/${MQTTLIB_S}.dll
SOURCE_FILES_S = ${filter-out ${MQTTCLIENT_DIR}/MQTTAsync.c, ${ALL_SOURCE_FILES}}
MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2
MQTTLIB_A = mqttv3a
MQTTDLL_A  = windows_ia32/${MQTTLIB_A}.dll
SOURCE_FILES_A = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c ${MQTTCLIENT_DIR}/SSLSocket.c, ${ALL_SOURCE_FILES}}
MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2
MQTTLIB_AS = mqttv3as
MQTTDLL_AS  = windows_ia32/${MQTTLIB_AS}.dll
SOURCE_FILES_AS = ${filter-out ${MQTTCLIENT_DIR}/MQTTClient.c, ${ALL_SOURCE_FILES}}
MANIFEST_S = mt -manifest ${MQTTDLL_S}.manifest -outputresource:${MQTTDLL_S}\;2

# compiler
CC = cl
CPPFLAGS = /D "WIN32" /D "_UNICODE" /D "UNICODE" /D "_CRT_SECURE_NO_WARNINGS"
CFLAGS = /nologo /c /O2 /W3 /Fd /MD /TC
INC =  /I ${MQTTCLIENT_DIR} /I ${MQTTCLIENT_DIR}/..
CPPFLAGS_S = ${CPPFLAGS} /D "OPENSSL"
INC_S = ${INC} /I ${OPENSSL_DIR}/inc32/

# linker 
LD = link
LINKFLAGS = /nologo /machine:x86 /manifest /dll
WINLIBS = kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
          advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib\
          odbc32.lib odbccp32.lib ws2_32.lib
IMP = /implib:${@:.dll=.lib}
LIBPDB = /pdb:${@:.dll=.pdb}
LIBMAP = /map:${@:.dll=.map}
WINLIBS_S = ${WINLIBS} crypt32.lib ssleay32.lib libeay32.lib
LIBPATH_S = /LIBPATH:${OPENSSL_DIR}/lib

# targets
all: ${MQTTDLL} ${MQTTDLL_A} ${MQTTDLL_AS} ${MQTTDLL_S}

${MQTTDLL}: ${SOURCE_FILES}  
    -mkdir windows_ia32
    -rm ${CURDIR}/MQTTAsync.obj
    ${CC} ${CPPFLAGS} ${CFLAGS} ${INC} /Fo ${SOURCE_FILES}
    ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS} *.obj /out:${MQTTDLL}
    ${MANIFEST}

${MQTTDLL_A}: ${SOURCE_FILES_A}  
    -mkdir windows_ia32
    -rm ${CURDIR}/MQTTClient.obj
    ${CC} ${CPPFLAGS} ${CFLAGS} ${INC} /Fo ${SOURCE_FILES_A}
    ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS} *.obj /out:${MQTTDLL_A}
    ${MANIFEST_A}    

${MQTTDLL_S}: ${SOURCE_FILES_S} 
    -mkdir windows_ia32
    -rm ${CURDIR}/MQTTAsync.obj
    ${CC} ${CPPFLAGS_S} ${CFLAGS} ${INC_S} /Fo ${SOURCE_FILES}
    ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS_S} ${LIBPATH_S} *.obj /out:${MQTTDLL_S}
    ${MANIFEST_S}

${MQTTDLL_AS}: ${SOURCE_FILES_AS} 
    -rm ${CURDIR}/MQTTClient.obj
    ${CC} ${CPPFLAGS_S} ${CFLAGS} ${INC_S} /Fo ${SOURCE_FILES_AS}
    ${LD} ${LINKFLAGS} ${IMP} ${LIBPDB} ${LIBMAP} ${WINLIBS_S} ${LIBPATH_S} *.obj /out:$(MQTTDLL_AS}
    $(MANIFEST_AS}

.PHONY : clean
clean: 
    -rm -f *.obj
    -rm -f -r windows_ia32 

Building the OpenSSL package

Build the OpenSSL package before you build the secure MQTT client libraries for C, mqttv3cs and mqttv3as. The build creates the libraries that are required to build a secure version of the MQTT client for C library, and the OpenSSL certificate management tool.

Before you begin

  1. iOSThe iOS makefile customization is for target devices that run iOS6. The customization might be different for earlier or later versions of iOS.
  2. WindowsThe Windows makefile customization is for 32-bit windows.

About this task

Download and install the OpenSSL package and any prerequisite software. Customize the OpenSSL makefiles, and build OpenSSL libraries for your target platform. On Windows and Linux, make also builds the OpenSSL key creation and management tool.

Procedure

  1. Install the OpenSSL package.
    1. Download the OpenSSL package from OpenSSL
      Important: Download and redistribution of the OpenSSL package is subject to stringent import and export regulation, and open source licensing conditions. Take careful note of the restrictions and warnings before you decide whether to download the package.
    2. Expand the compressed file contents into sdkroot.
      Look under the News tab on the OpenSSL site to find the download location of the latest package. The package is compressed as a tar file with the extension tar.gz. When expanded, the package creates a top-level folder opensslversion; for example openssl-1.0.1c. The examples refer to the path to the folder as %openssl% on Windows and $openssl on iOS; for example, on Windows, %openssl% is sdkroot\openssl-1.0.1c.
      Tip: Check the directory path that is created by extracting the OpenSSL package. Some packages have duplicate levels of the opensslversion folder.
  2. Optional: Windows On Windows, download and install perl. See perl.org.

    For the example, perl was downloaded from ActivePerl Downloads.

  3. Optional: iOSOn iOS, create three more directories.
    • $ssarm7 ≡ $openssl/arm7
    • $sslarm7s ≡ $openssl/arm7s
    • $ssli386 ≡ $openssl/i386
    For iOS you must build the OpenSSL package for three different hardware platforms.
  4. Generate the OpenSSL makefile to build the OpenSSL package for your hardware and operating system.
    1. Open a command window in the %openssl% or $openssl directory.
    2. Run the Configure perl command with the appropriate parameters.
      • Windows
        perl Configure VC-WIN32 enable-capieng no-asm no-idea no-mdc2 no-rc5 --prefix=%openssl%
        ms\do_ms.bat
      • iOS
        ./Configure BSD-generic32 no-idea no-mdc2 no-rc5 --prefix=$openssl
  5. iOSOn iOS, customize the generated OpenSSL makefile for different Apple devices.
    1. Make three copies of the generated makefile, $openssl/Makefile
      • $openssl/Makefile_armv7
      • $openssl/Makefile_armv7s
      • $openssl/Makefile_i386
    2. Change the CC=gcc statement in each makefile.
      The CC=gcc statement is on line 62, or thereabouts. Change it to the following commands:
      $openssl/Makefile_armv7
      CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7
      $openssl/Makefile_armv7s
      CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7s
      $openssl/Makefile_i386
      CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch i386
    3. Change the CFLAG=... statement in each makefile.

      The statement is on line 63 or thereabouts (broken into three lines for readability):

      CFLAG= -DOPENSSL_THREADS -pthread -D_THREAD_SAFE
      -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS
      -O3 -fomit-frame-pointer -Wall
      

      The location of the SDKs shown is dependent on your Xcode installation choices. The version of the SDKs is dependent on the operating system level you are building the makefile for.

      iPhone simulator
      The iPhone simulator makefile is $openssl/Makefile_i386.
      CFLAG= -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk
      -DOPENSSL_THREADS -pthread -D_THREAD_SAFE 
      -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS
      -O3 -fomit-frame-pointer -Wall
      
      iOS
      The iOS makefiles are $openssl/Makefile_arm7 and $openssl/Makefile_arm7s.
      CFLAG= -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk
      -DOPENSSL_THREADS -pthread -D_THREAD_SAFE 
      -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DTERMIOS
      -O3 -fomit-frame-pointer -Wall
      
  6. Run the generated makefile.
    • Windows
      nmake -clean
      nmake -f ms\nt.mak
      nmake -f ms\nt.mak install
    • iOSOn iOS:
      make clean
      make -f $openssl/Makefile_arm7
      mv $openssl/libcrypto.a $ssarm7/libcrypto.a
      mv $openssl/libssl.a $ssarm7/libssl.a
      make clean
      make -f $openssl/Makefile_arm7s
      mv $openssl/libcrypto.a $sslarm7s/libcrypto.a
      mv $openssl/libssl.a $sslarm7s/libssl.a
      make clean
      make -f $openssl/Makefile_i386
      mv $openssl/libcrypto.a $ssli386/libcrypto.a
      mv $openssl/libssl.a $ssli386/libssl.a
      

Results

The build generates the shared libraries, lib, and header files that are required to build secure versions of the MQTT client library for C.