How to write u-boot environment variables in mmcblk0boot0 instead of mmcblk0p1 - android

I'm working on board bring-up of a custom iMX6 based board. I'm using the Android package from iMX6 Sabre SD board, and have got most of the things working with booting from eMMC which on on-board, but I'm facing issue with 'saveenv' of u-boot.
Firstly, everytime on boot there is a print :
*** Warning - bad CRC or MMC, using default environment
I search online and found that we have to do 'saveenv' once to let this error go away. So I did saveenv but after that the board doesn't boot completely and got stuck on 'Uncompressing Linux ...' !
I then boot-up the board using SD card and got the hexdump of /dev/block/mmcblk0boot0 and /dev/block/mmcblk0p1 (both are eMMC partitions, SD card is dev/block/mmcblk1)
To my surprise, from hexdump I found that 'saveenv' writes the environment variable data to /dev/block/mmcblk0p1 and not /dev/block/mmcblk0boot0 which was the reason the board didn't boot-up as boot.img is in dev/block/mmcblk0p1 partition was corrupted by u-boot doing saveenv and over-writing the boot.img data.
So, my question is how can I change the u-boot code to modify it to read and save environment variables on /dev/block/mmcblk0boot0 instead of /dev/block/mmcblk0p1
I'm trying to dig into the code and so far I have found that common/env_mmc.c is the file which has all functions to read/write environment variables, and include/configs/mx6solo_sabresd.h includes the configuration of my board.
P.S. : The u-boot itself is located in /dev/block/mmcblk0boot0
Edit : Below the information regarding partitions :
root#imx6:/ # cat /proc/partitions
major minor #blocks name
31 0 64 mtdblock0
179 0 3833856 mmcblk0
179 1 15640 mmcblk0p1
179 2 7840 mmcblk0p2
179 3 1 mmcblk0p3
179 5 500024 mmcblk0p5
179 6 500024 mmcblk0p6
179 7 78136 mmcblk0p7
259 0 500024 mmcblk0p8
259 1 19544 mmcblk0p9
259 2 2212568 mmcblk0p10
179 16 1024 mmcblk0boot1
179 8 1024 mmcblk0boot0
179 24 3887104 mmcblk1
179 25 7168 mmcblk1p1
179 26 484352 mmcblk1p2
179 27 1 mmcblk1p3
179 29 289792 mmcblk1p5
179 30 550912 mmcblk1p6
179 31 570368 mmcblk1p7
259 3 799744 mmcblk1p8
root#imx6:/ #
root#imx6:/ # cat /proc/mtd
dev: size erasesize name
mtd0: 00010000 00008000 "bootloader"
mtd1: 00000000 00000000 "kernel"
root#imx6:/ #
root#imx6:/ # fdisk -l /dev/block/mmcblk0
Disk /dev/block/mmcblk0: 3925 MB, 3925868544 bytes
4 heads, 16 sectors/track, 119808 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk0p1 1 489 15640 83 Linux
/dev/block/mmcblk0p2 490 734 7840 83 Linux
/dev/block/mmcblk0p3 735 119808 3810368 5 Extended
/dev/block/mmcblk0p5 735 16360 500024 83 Linux
/dev/block/mmcblk0p6 16361 31986 500024 83 Linux
/dev/block/mmcblk0p7 31987 34428 78136 83 Linux
/dev/block/mmcblk0p8 34429 50054 500024 83 Linux
/dev/block/mmcblk0p9 50055 50665 19544 83 Linux
/dev/block/mmcblk0p10 50666 119808 2212568 83 Linux
root#imx6:/ #
root#imx6:/ # fdisk -l /dev/block/mmcblk0boot0
Disk /dev/block/mmcblk0boot0: 1 MB, 1048576 bytes
4 heads, 16 sectors/track, 32 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk /dev/block/mmcblk0boot0 doesn't contain a valid partition table
root#imx6:/ # fdisk -l /dev/block/mmcblk0boot1
Disk /dev/block/mmcblk0boot1: 1 MB, 1048576 bytes
4 heads, 16 sectors/track, 32 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Disk /dev/block/mmcblk0boot1 doesn't contain a valid partition table
root#imx6:/ #
U-Boot config file :
/*
* Copyright (C) 2012 Freescale Semiconductor, Inc.
*
* Configuration settings for the MX6DL SabreSD Freescale board.
* The board is configured with SOLO and 32-bit DDR bus-width.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#ifndef __CONFIG_H
#define __CONFIG_H
#include <asm/arch/mx6.h>
/* High Level Configuration Options */
#define CONFIG_ARMV7 /* This is armv7 Cortex-A9 CPU core */
#define CONFIG_MXC
#define CONFIG_MX6DL
#define CONFIG_MX6DL_DDR3
#define CONFIG_MX6DL_SABRESD
#define CONFIG_DDR_32BIT /* for DDR 32bit */
#define CONFIG_FLASH_HEADER
#define CONFIG_FLASH_HEADER_OFFSET 0x400
#define CONFIG_MX6_CLK32 32768
#define CONFIG_SKIP_RELOCATE_UBOOT
#define CONFIG_ARCH_CPU_INIT
#undef CONFIG_ARCH_MMU /* disable MMU first */
#define CONFIG_L2_OFF /* disable L2 cache first*/
#define CONFIG_MX6_HCLK_FREQ 24000000
#define CONFIG_DISPLAY_CPUINFO
#define CONFIG_DISPLAY_BOARDINFO
#define CONFIG_SYS_64BIT_VSPRINTF
#define BOARD_LATE_INIT
#define CONFIG_CMDLINE_TAG /* enable passing of ATAGs */
#define CONFIG_SERIAL_TAG
#define CONFIG_REVISION_TAG
#define CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG
#define CONFIG_MXC_GPIO
/*
* Size of malloc() pool
*/
#define CONFIG_SYS_MALLOC_LEN (2 * 1024 * 1024)
/* size in bytes reserved for initial data */
#define CONFIG_SYS_GBL_DATA_SIZE 128
/*
* Hardware drivers
*/
#define CONFIG_MXC_UART
#define CONFIG_UART_BASE_ADDR UART1_BASE_ADDR
/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE
#define CONFIG_CONS_INDEX 1
#define CONFIG_BAUDRATE 115200
#define CONFIG_SYS_BAUDRATE_TABLE {9600, 19200, 38400, 57600, 115200}
/***********************************************************
* Command definition
***********************************************************/
#include <config_cmd_default.h>
#define CONFIG_CMD_PING
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_MII
#define CONFIG_CMD_NET
#define CONFIG_NET_RETRY_COUNT 100
#define CONFIG_NET_MULTI 1
#define CONFIG_BOOTP_SUBNETMASK
#define CONFIG_BOOTP_GATEWAY
#define CONFIG_BOOTP_DNS
#define CONFIG_CMD_SPI
#define CONFIG_CMD_I2C
#define CONFIG_CMD_IMXOTP
/* Enable below configure when supporting nand */
#define CONFIG_CMD_SF
#define CONFIG_CMD_MMC
#define CONFIG_CMD_ENV
#define CONFIG_CMD_REGUL
#define CONFIG_CMD_CLOCK
#define CONFIG_REF_CLK_FREQ CONFIG_MX6_HCLK_FREQ
#undef CONFIG_CMD_IMLS
#define CONFIG_CMD_IMX_DOWNLOAD_MODE
#define CONFIG_BOOTDELAY 3
#define CONFIG_PRIME "FEC0"
#define CONFIG_LOADADDR 0x10800000 /* loadaddr env var */
#define CONFIG_RD_LOADADDR (CONFIG_LOADADDR + 0x300000)
#define CONFIG_EXTRA_ENV_SETTINGS \
"netdev=eth0\0" \
"ethprime=FEC0\0" \
"uboot=u-boot.bin\0" \
"kernel=uImage\0" \
"nfsroot=/opt/eldk/arm\0" \
"bootargs_base=setenv bootargs console=ttymxc0,115200 nosmp\0" \
"bootargs_nfs=setenv bootargs ${bootargs} root=/dev/nfs " \
"ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
"bootcmd_net=run bootargs_base bootargs_nfs; " \
"tftpboot ${loadaddr} ${kernel}; bootm\0" \
"bootargs_mmc=setenv bootargs ${bootargs} ip=dhcp " \
"root=/dev/mmcblk0p1 rootwait\0" \
"bootcmd_mmc=run bootargs_base bootargs_mmc; " \
"mmc dev 3; " \
"mmc read ${loadaddr} 0x800 0x2000; bootm\0" \
"bootcmd=run bootcmd_net\0" \
#define CONFIG_ARP_TIMEOUT 200UL
/*
* Miscellaneous configurable options
*/
#define CONFIG_SYS_LONGHELP /* undef to save memory */
#define CONFIG_SYS_PROMPT "MX6Solo SABRESD U-Boot > "
#define CONFIG_AUTO_COMPLETE
#define CONFIG_SYS_CBSIZE 1024 /* Console I/O Buffer Size */
/* Print Buffer Size */
#define CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
#define CONFIG_SYS_MAXARGS 16 /* max number of command args */
#define CONFIG_SYS_BARGSIZE CONFIG_SYS_CBSIZE /* Boot Argument Buffer Size */
#define CONFIG_SYS_MEMTEST_START 0x10000000 /* memtest works on */
#define CONFIG_SYS_MEMTEST_END 0x10010000
#undef CONFIG_SYS_CLKS_IN_HZ /* everything, incl board info, in Hz */
#define CONFIG_SYS_LOAD_ADDR CONFIG_LOADADDR
#define CONFIG_SYS_HZ 1000
#define CONFIG_CMDLINE_EDITING
#define CONFIG_FEC0_IOBASE ENET_BASE_ADDR
#define CONFIG_FEC0_PINMUX -1
#define CONFIG_FEC0_MIIBASE -1
#define CONFIG_GET_FEC_MAC_ADDR_FROM_IIM
#define CONFIG_MXC_FEC
#define CONFIG_FEC0_PHY_ADDR 1
#define CONFIG_ETH_PRIME
#define CONFIG_RMII
#define CONFIG_CMD_MII
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_PING
#define CONFIG_IPADDR 192.168.1.103
#define CONFIG_SERVERIP 192.168.1.101
#define CONFIG_NETMASK 255.255.255.0
/*
* OCOTP Configs
*/
#ifdef CONFIG_CMD_IMXOTP
#define CONFIG_IMX_OTP
#define IMX_OTP_BASE OCOTP_BASE_ADDR
#define IMX_OTP_ADDR_MAX 0x7F
#define IMX_OTP_DATA_ERROR_VAL 0xBADABADA
#endif
/*
* I2C Configs
*/
#ifdef CONFIG_CMD_I2C
#define CONFIG_HARD_I2C
#define CONFIG_I2C_MXC 1
#define CONFIG_SYS_I2C_PORT I2C2_BASE_ADDR
#define CONFIG_SYS_I2C_SPEED 100000
#define CONFIG_SYS_I2C_SLAVE 0x8
#define CONFIG_MX6_INTER_LDO_BYPASS 0
#endif
/*
* SPI Configs
*/
#ifdef CONFIG_CMD_SF
#define CONFIG_FSL_SF
#define CONFIG_SPI_FLASH_IMX_M25PXX
#define CONFIG_SPI_FLASH_CS 0
#define CONFIG_IMX_ECSPI
#define IMX_CSPI_VER_2_3 1
#define MAX_SPI_BYTES (64 * 4)
#endif
/* Regulator Configs */
#ifdef CONFIG_CMD_REGUL
#define CONFIG_ANATOP_REGULATOR
#define CONFIG_CORE_REGULATOR_NAME "vdd1p1"
#define CONFIG_PERIPH_REGULATOR_NAME "vdd1p1"
#endif
/*
* MMC Configs
*/
#ifdef CONFIG_CMD_MMC
#define CONFIG_MMC
#define CONFIG_GENERIC_MMC
#define CONFIG_IMX_MMC
#define CONFIG_SYS_FSL_USDHC_NUM 4
#define CONFIG_SYS_FSL_ESDHC_ADDR 0
#define CONFIG_SYS_MMC_ENV_DEV 2
#define CONFIG_DOS_PARTITION
#define CONFIG_CMD_FAT
#define CONFIG_CMD_EXT2
/* detect whether SD1, 2, 3, or 4 is boot device */
#define CONFIG_DYNAMIC_MMC_DEVNO
/* SD3(Mircro SD) 4 bit, SD4(EMMC) are 8 bit */
#define CONFIG_MMC_8BIT_PORTS 0x8
/* Setup target delay in DDR mode for each SD port */
#define CONFIG_GET_DDR_TARGET_DELAY
#endif
/*
* GPMI Nand Configs
*/
/* #define CONFIG_CMD_NAND */
#ifdef CONFIG_CMD_NAND
#define CONFIG_NAND_GPMI
#define CONFIG_GPMI_NFC_SWAP_BLOCK_MARK
#define CONFIG_GPMI_NFC_V2
#define CONFIG_GPMI_REG_BASE GPMI_BASE_ADDR
#define CONFIG_BCH_REG_BASE BCH_BASE_ADDR
#define NAND_MAX_CHIPS 8
#define CONFIG_SYS_NAND_BASE 0x40000000
#define CONFIG_SYS_MAX_NAND_DEVICE 1
/* NAND is the unique module invoke APBH-DMA */
#define CONFIG_APBH_DMA
#define CONFIG_APBH_DMA_V2
#define CONFIG_MXS_DMA_REG_BASE ABPHDMA_BASE_ADDR
#endif
/*-----------------------------------------------------------------------
* Stack sizes
*
* The stack sizes are set up in start.S using the settings below
*/
#define CONFIG_STACKSIZE (128 * 1024) /* regular stack */
/*-----------------------------------------------------------------------
* Physical Memory Map
*/
#define CONFIG_NR_DRAM_BANKS 1
#define PHYS_SDRAM_1 CSD0_DDR_BASE_ADDR
#define PHYS_SDRAM_1_SIZE (1u * 1024 * 1024 * 1024)
#define iomem_valid_addr(addr, size) \
(addr >= PHYS_SDRAM_1 && addr <= (PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
#define CONFIG_SYS_NO_FLASH
/* Monitor at beginning of flash */
#define CONFIG_FSL_ENV_IN_MMC
/* #define CONFIG_FSL_ENV_IN_NAND */
#define CONFIG_ENV_SECT_SIZE (8 * 1024)
#define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
#if defined(CONFIG_FSL_ENV_IN_NAND)
#define CONFIG_ENV_IS_IN_NAND 1
#define CONFIG_ENV_OFFSET 0x100000
#elif defined(CONFIG_FSL_ENV_IN_MMC)
#define CONFIG_ENV_IS_IN_MMC 1
#define CONFIG_ENV_OFFSET (768 * 1024)
#elif defined(CONFIG_FSL_ENV_IN_SF)
#define CONFIG_ENV_IS_IN_SPI_FLASH 1
#define CONFIG_ENV_SPI_CS 1
#define CONFIG_ENV_OFFSET (768 * 1024)
#else
#define CONFIG_ENV_IS_NOWHERE 1
#endif
/* #define CONFIG_SPLASH_SCREEN */
/* #define CONFIG_MXC_EPDC */
/*
* SPLASH SCREEN Configs
*/
//#define CONFIG_SPLASH_SCREEN
#ifdef CONFIG_SPLASH_SCREEN
/*
* Framebuffer and LCD
*/
#define CONFIG_LCD
#define CONFIG_FB_BASE (TEXT_BASE + 0x300000)
#define CONFIG_SYS_CONSOLE_IS_IN_ENV
#ifdef CONFIG_MXC_EPDC
#undef LCD_TEST_PATTERN
/* #define CONFIG_SPLASH_IS_IN_MMC 1 */
#define LCD_BPP LCD_MONOCHROME
/* #define CONFIG_SPLASH_SCREEN_ALIGN 1 */
#define CONFIG_MXC_EPDC 1
#define CONFIG_WORKING_BUF_ADDR (TEXT_BASE + 0x100000)
#define CONFIG_WAVEFORM_BUF_ADDR (TEXT_BASE + 0x200000)
#define CONFIG_WAVEFORM_FILE_OFFSET 0x600000
#define CONFIG_WAVEFORM_FILE_SIZE 0xF0A00
#define CONFIG_WAVEFORM_FILE_IN_MMC
#ifdef CONFIG_SPLASH_IS_IN_MMC
#define CONFIG_SPLASH_IMG_OFFSET 0x4c000
#define CONFIG_SPLASH_IMG_SIZE 0x19000
#endif
#else /* !CONFIG_MXC_EPDC */
#define CONFIG_IPU_V3H
#define CONFIG_VIDEO_MX5
#define CONFIG_IPU_CLKRATE 260000000
#define CONFIG_SYS_CONSOLE_ENV_OVERWRITE
#define CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
#define LCD_BPP LCD_COLOR16
#define CONFIG_CMD_BMP
#define CONFIG_BMP_8BPP
#define CONFIG_SPLASH_SCREEN_ALIGN
#define CONFIG_SYS_WHITE_ON_BLACK
#define CONFIG_IMX_PWM
#define IMX_PWM1_BASE PWM1_BASE_ADDR
#define IMX_PWM2_BASE PWM2_BASE_ADDR
#endif
#endif /* CONFIG_SPLASH_SCREEN */
#endif /* __CONFIG_H */

Related

someone can tell me why I can't get the cpp log in dmesg or logcat?

I add some code log at below in android automotive10 source code
diff --git a/frameworks/av/services/audiopolicy/service/AudioPolicyService.cpp b/frameworks/av/services/audiopolicy/service/AudioPolicyService.cpp
index ad452434af..78ee4f80f6 100755
--- a/frameworks/av/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/frameworks/av/services/audiopolicy/service/AudioPolicyService.cpp
## -16,7 +16,10 ##
#define LOG_TAG "AudioPolicyService"
//#define LOG_NDEBUG 0
-
+//I add
+#include <android/log.h>
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
+// end
#include "Configuration.h"
#undef __STRICT_ANSI__
#define __STDINT_LIMITS
## -65,6 +68,10 ## AudioPolicyService::AudioPolicyService()
void AudioPolicyService::onFirstRef()
{
+//I add
+ printf("------------liwx:AudioPolicyService::onFirstRef");
+ char * log =(char*) "liwx_tag";
+ LOGI("------------liwx AudioPolicyService::onFirstRef,%s\n",log);
{
Mutex::Autolock _l(mLock);
I knew some C++ log code can't capture Android, so I add .H file, but it was unuseless
someone can help me, thanks

PJSIP ndk configuration issue in centos

I am trying to use pjSip for my android application and following pjsip instructions. My system configurations are centos 7.4 64 bit .
I have downloaded latest ndk and pjsip code.
But when I am running the commands I am getting below error.
One more thing I noticed, confige.log aslo showing
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C
[root#localhost pjproject-2.7.1]# ./configure-android
configure-android: APP_PLATFORM not specified, using android-27
configure-android: TARGET_ABI not specified, using armeabi
configure-android: calling ./configure with env vars:
CC = /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
CXX = /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
CFLAGS = --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include
CXXFLAGS = -shared --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti
LDFLAGS = --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -L/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/
LIBS = -lgnustl_static -lc -lgcc
AR = /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
RANLIB = /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
TARGET_HOST = arm-linux-androideabi
TARGET_ABI = armeabi
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking target system type... arm-unknown-linux-androideabi
checking for arm-linux-androideabi-gcc... /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc accepts -g... yes
checking for /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to accept ISO C89... unsupported
checking whether we are using the GNU C++ compiler... yes
checking whether /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ accepts -g... yes
checking for arm-linux-androideabi-ranlib... /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
checking for arm-linux-androideabi-ar... /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
checking for pthread_create in -lpthread... no
checking for puts in -lwsock32... no
checking for puts in -lws2_32... no
checking for puts in -lole32... no
checking for puts in -lwinmm... no
checking for puts in -lsocket... no
checking for puts in -lrt... no
checking for sin in -lm... yes
checking for uuid_generate in -luuid... no
checking for uuid_generate in -luuid... (cached) no
checking for library containing gethostbyname... none required
Setting PJ_M_NAME to arm
checking memory alignment... 4 bytes (default)
checking how to run the C preprocessor... /lib/cpp
aconfigure: error: in `/root/ROOTSIPFOLDER/pjproject-2.7.1':
aconfigure: error: C preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
Below is my configue.log result.
aconfigure:2916: /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -v >&5
Using built-in specs.
COLLECT_GCC=/root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
COLLECT_LTO_WRAPPER=/root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper
Target: arm-linux-androideabi
.......................................
aconfigure:3269: /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -c -g --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti conftest.c >&5
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C
aconfigure:3269: $? = 0
aconfigure:3279: result: yes
aconfigure:3296: checking for /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to accept ISO C89
aconfigure:3359: /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -c --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti conftest.c >&5
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C
conftest.c:10:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
aconfigure:3359: $? = 1
aconfigure: failed program was:
/* confdefs.h */
#define PACKAGE_NAME "pjproject"
#define PACKAGE_TARNAME "pjproject"
#define PACKAGE_VERSION "2.x"
#define PACKAGE_STRING "pjproject 2.x"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
char **p;
int i;
{
return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
char *s;
va_list v;
va_start (v,p);
s = g (p, va_arg (v,int));
va_end (v);
return s;
}
arm-linux-androideabi-gcc: error: unrecognized command line option '-std'
aconfigure:3359: $? = 1
aconfigure: failed program was:
/* confdefs.h */
#define PACKAGE_NAME "pjproject"
#define PACKAGE_TARNAME "pjproject"
#define PACKAGE_VERSION "2.x"
#define PACKAGE_STRING "pjproject 2.x"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
char **p;
int i;
{
return p[i];
}Satic char *f (char * (*g) (char **, int), char **p, ...)
{
char *s;
va_list v;
va_start (v,p);
s = g (p, va_arg (v,int));
va_end (v);
return s;
}
* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
function prototypes and stuff, but not '\xHH' hex character constants.
These don't provoke an error unfortunately, instead are silently treated
as 'x'. The following induces an error, until -std is added to get
proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
array size at least. It's necessary to write '\x00'==0 to get something
that's true only with -std. */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];
/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
inside strings and character constants. */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
int argc;
char **argv;
int
main ()
{
return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
;
return 0;
}
aconfigure:3359: /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -Ae -c --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti conftest.c >&5
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C
<command-line>:0:1: error: missing '(' after predicate
conftest.c:10:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
aconfigure:3359: $? = 1
aconfigure: failed program was:
/* confdefs.h */
#define PACKAGE_NAME "pjproject"
#define PACKAGE_TARNAME "pjproject"
#define PACKAGE_VERSION "2.x"
#define PACKAGE_STRING "pjproject 2.x"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
char **p;
int i;
{
return p[i];
}
| static char *f (char * (*g) (char **, int), char **p, ...)
{
char *s;
va_list v;
va_start (v,p);
s = g (p, va_arg (v,int));
va_end (v);
return s;
}
/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
function prototypes and stuff, but not '\xHH' hex character constants.
These don't provoke an error unfortunately, instead are silently treated
as 'x'. The following induces an error, until -std is added to get
proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
array size at least. It's necessary to write '\x00'==0 to get something
that's true only with -std. */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];
/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
inside strings and character constants. */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
int argc;
char **argv;
int
main ()
{
return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
;
return 0;
}
aconfigure:3359: /root/ROOTSIPFOLDER/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -Aa -D_HPUX_SOURCE -c --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include -I/root/ROOTSIPFOLDER/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti conftest.c >&5
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C
<command-line>:0:1: error: missing '(' after predicate
conftest.c:10:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
aconfigure:3359: $? = 1
aconfigure: failed program was:
/* confdefs.h */
#define PACKAGE_NAME "pjproject"
#define PACKAGE_TARNAME "pjproject"
#define PACKAGE_VERSION "2.x"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
/* end confdefs.h. */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
char **p;
int i;
{
return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
char *s;
va_list v;
va_start (v,p);
s = g (p, va_arg (v,int));
va_end (v);
return s;
}
| Syntax error
aconfigure:4534: /lib/cpp --sysroot=/root/ROOTSIPFOLDER/android-ndk-r16b/platforms/android-27/arch-arm -fexceptions -frtti conftest.c
cc1: warning: command line option '-frtti' is valid for C++/ObjC++ but not for C [enabled by default]
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/syslimits.h:7:0,
from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/limits.h:34,
from conftest.c:13:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/limits.h:168:61: error: no include path in which to search for limits.h
#include_next <limits.h> /* recurse down to the real one */
^
aconfigure:4534: $? = 1
aconfigure: failed program was:
/* confdefs.h */
#define PACKAGE_NAME "pjproject"
#define PACKAGE_TARNAME "pjproject"
#define PACKAGE_VERSION "2.x"
#define PACKAGE_STRING "pjproject 2.x"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define HAVE_LIBM 1
#define PJ_M_NAME "arm"
#define PJ_POOL_ALIGNMENT 4
/* end confdefs.h. */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
Syntax error
aconfigure:4564: error: in `/root/ROOTSIPFOLDER/pjproject-2.7.1':
aconfigure:4566: error: C preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
Above error are not addressed any where and I have tried every thing they
have suggested.
I have followed every step very carefully and now dont know where I am doing wrong. I have tried the same on centos 6.9 but with no success. Initially I tried same on windows with sygwin what there also I was not able to run in.
I wonder I there is some issue with my machine or I am doing some thing wrong
Sorry I am not able to format the log. Hope I can get some help over here.
Looks like the project's build script is a few revisions out of date: https://github.com/pjsip/pjproject/blob/master/configure-android#L180. The headers moved to a merged tree (rather than per-API and per-arch) in r14 and the deprecated headers were removed in r16.
You might want to try using a standalone toolchain to build. You might want to try using one of these with the non-android configure script first (standalone toolchains are designed to be dropped into arbitrary autoconf systems that don't support Android themselves), but if that doesn't work then try it with configure-android.

__android_log_print equivalent for printf

I am trying to port this logging statement to work, so it will run on linux and android my #define'ing it:
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
I have cross-compiled my app to run on both Linux and Android. However, as linux doesn't have the equivalent I have tried to do my own.
/** ANDROID */
#if defined(__ANDROID__)
#include <android/log.h>
#define LOG_ERROR ANDROID_LOG_ERROR
#define LOG(PRIORITY, fmt, ...) __android_log_print(ANDROID_LOG_UNKNOWN, LOG_TAG, fmt, ##__VA_ARGS__)
/** LINUX */
#elif defined(linux) || defined(__linux) || defined(__linux__)
#define LOG_ERROR LINUX_LOG_ERROR
#define LOG(PRIORITY, fmt, ...) printf(PRIORITY fmt, ##__VA_ARGS__)
#endif
And then using it like this when running under linux
LOG(LOG_ERROR, "Testing loggging [ %d ]", test);
Is there a better way to do this?
Many thanks for any suggestions,
I managed to solve it this way. Here is the complete solution.
This would be in a header file
typedef enum levels_tag levels_e;
enum levels_tag {
LOG_UNKNOWN = 0,
LOG_DEFAULT,
LOG_VERBOSE,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_FATAL,
LOG_SILENT,
LOG_LAST
};
/* ANDRIOD IMPLEMENTATION */
#if defined( __ARM_EABI__)
#include <android/log.h>
levels_e levels[LOG_LAST] = {LOG_UNKNOWN,
LOG_DEFAULT,
LOG_VERBOSE,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_FATAL,
LOG_SILENT};
#define LOG_TAG "MODULE_LOG_SIP"
#define LOGGING(PRIORITY, fmt, ...) __android_log_print(levels[PRIORITY], LOG_TAG, fmt, ##__VA_ARGS__)
/* LINUX IMPLEMENTATION */
#elif defined(linux) || defined(__linux) || defined(__linux__)
char *priority_levels[] = {"UNKNOWN",
"DEFAULT",
"VERBOSE",
"DEBUG",
"INFO",
"WARN",
"ERROR",
"FATAL",
"SILENT",
NULL };
#define LOGGING(PRIORITY, fmt, ...) \
do { \
char *priority = priority_levels[PRIORITY]; \
printf("%s/%s:%d [%s] " fmt " \n", __FILE__, __func__, __LINE__, priority, ##__VA_ARGS__); \
} while(0)
#endif
#define LOG(PRIORITY, fmt, ...) LOGGING(PRIORITY, fmt, ##__VA_ARGS__)
And in your source files you would just call the LOG macro like this:
LOG(LOG_FATAL, "Failed to create and initialize application instance [ %d ]", errno);
Now if you were to compile on linux it would use the printf statement. And if you were to compile on Android it would use the __android_log_print statement. Both would produce the same formatted output.
Hope this helps someone else.
You can also use family of syslog() functions to make output to system log instead of stdout/stderr (see syslog.h):
void openlog(const char *ident, int option, int facility);
void syslog(int priority, const char *format, ...);
void closelog(void);
Logs can be viewed in /var/log (file depends on options of syslog, by default in many systems logs are in the file "messages"). Sometimes this way is a better than stdout/stderr, but you have to use openlog/closelog. Unfortunately, syslog's priorities are different comparing to android priorities and thus it doesn't allow simple macro definition with transparent priorities.Syslog priorities:
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
Priorities of android log:
/*
* Android log priority values, in ascending priority order.
*/
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
} android_LogPriority;

How to build static zeromq under ndk for android?

I try to build zmq for android follow http://www.zeromq.org/build:android
but it do not work, link error for some reason i do not know.
I google it a lot and I find no way to make it right.
so I give up to build it in official way and I finally build it by writing my own Android.mk,
my OS is OSX 10.8.3, and ndk is r8e, zeromq is 3.2.2
.1. I copy the hello-jni folder under android-ndk-r8e/samples/ and rename it to hello-zmq.
.2. copy all the files under zeromq-3.2.2/src to hello-zmq/jni
.3. modify platform.hpp like (if no platform.hpp there, make it under hello-zmq/jni):
/* Define to 1 if you have the <alloca.h> header file. */
#define HAVE_ALLOCA_H 1
/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
/* Define to 1 if you have the `clock_gettime' function. */
/* #undef HAVE_CLOCK_GETTIME */
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
/* Define to 1 if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 1
/* Define to 1 if you have the `freeifaddrs' function. */
#define HAVE_FREEIFADDRS 1
/* Define to 1 if you have the `gethrtime' function. */
/* #undef HAVE_GETHRTIME */
/* Define to 1 if you have the `getifaddrs' function. */
#define HAVE_GETIFADDRS 1
/* Define to 1 if you have the `gettimeofday' function. */
#define HAVE_GETTIMEOFDAY 1
/* Define to 1 if you have the <ifaddrs.h> header file. */
#define HAVE_IFADDRS_H 1
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* Define to 1 if you have the `iphlpapi' library (-liphlpapi). */
/* #undef HAVE_LIBIPHLPAPI */
/* Define to 1 if you have the `nsl' library (-lnsl). */
/* #undef HAVE_LIBNSL */
/* Define to 1 if you have the `pthread' library (-lpthread). */
#define HAVE_LIBPTHREAD 1
/* Define to 1 if you have the `rpcrt4' library (-lrpcrt4). */
/* #undef HAVE_LIBRPCRT4 */
/* Define to 1 if you have the `rt' library (-lrt). */
/* #undef HAVE_LIBRT */
/* Define to 1 if you have the `socket' library (-lsocket). */
/* #undef HAVE_LIBSOCKET */
/* Define to 1 if you have the `ws2_32' library (-lws2_32). */
/* #undef HAVE_LIBWS2_32 */
/* Define to 1 if you have the <limits.h> header file. */
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#define HAVE_MEMSET 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define to 1 if you have the <netinet/tcp.h> header file. */
#define HAVE_NETINET_TCP_H 1
/* Define to 1 if you have the `perror' function. */
#define HAVE_PERROR 1
/* Define to 1 if you have the `socket' function. */
#define HAVE_SOCKET 1
/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/eventfd.h> header file. */
/* #undef HAVE_SYS_EVENTFD_H */
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/uio.h> header file. */
#define HAVE_SYS_UIO_H 1
/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Define to 1 if you have the <windows.h> header file. */
/* #undef HAVE_WINDOWS_H */
/* Define to 1 if the system has the type `_Bool'. */
/* #undef HAVE__BOOL */
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#define LT_OBJDIR ".libs/"
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
/* #undef NO_MINUS_C_MINUS_O */
/* Name of package */
#define PACKAGE "zeromq"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "zeromq-dev#lists.zeromq.org"
/* Define to the full name of this package. */
#define PACKAGE_NAME "zeromq"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "zeromq 3.2.2"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "zeromq"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "3.2.2"
/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#define TIME_WITH_SYS_TIME 1
/* Version number of package */
#define VERSION "3.2.2"
/* Force to use mutexes */
/* #undef ZMQ_FORCE_MUTEXES */
/* Have AIX OS */
/* #undef ZMQ_HAVE_AIX */
/* Have Android OS */
#define ZMQ_HAVE_ANDROID 1
/* Have Cygwin */
/* #undef ZMQ_HAVE_CYGWIN */
/* Have eventfd extension. */
//#define ZMQ_HAVE_EVENTFD 1
/* Have FreeBSD OS */
/* #undef ZMQ_HAVE_FREEBSD */
/* Have HPUX OS */
/* #undef ZMQ_HAVE_HPUX */
/* Have ifaddrs.h header. */
//#define ZMQ_HAVE_IFADDRS 1
/* Have Linux OS */
#define ZMQ_HAVE_LINUX 1
/* Have MinGW32 */
/* #undef ZMQ_HAVE_MINGW32 */
/* Have NetBSD OS */
/* #undef ZMQ_HAVE_NETBSD */
/* Have OpenBSD OS */
/* #undef ZMQ_HAVE_OPENBSD */
/* Have OpenPGM extension */
/* #undef ZMQ_HAVE_OPENPGM */
/* Have DarwinOSX OS */
//#define ZMQ_HAVE_OSX 1
/* Have QNX Neutrino OS */
/* #undef ZMQ_HAVE_QNXNTO */
/* Whether SOCK_CLOEXEC is defined and functioning. */
/* #undef ZMQ_HAVE_SOCK_CLOEXEC */
/* Have Solaris OS */
/* #undef ZMQ_HAVE_SOLARIS */
/* Whether SO_KEEPALIVE is supported. */
//#define ZMQ_HAVE_SO_KEEPALIVE 1
/* Whether TCP_KEEPALIVE is supported. */
//#define ZMQ_HAVE_TCP_KEEPALIVE 1
/* Whether TCP_KEEPCNT is supported. */
/* #undef ZMQ_HAVE_TCP_KEEPCNT */
/* Whether TCP_KEEPIDLE is supported. */
/* #undef ZMQ_HAVE_TCP_KEEPIDLE */
/* Whether TCP_KEEPINTVL is supported. */
/* #undef ZMQ_HAVE_TCP_KEEPINTVL */
/* Have uio.h header. */
#define ZMQ_HAVE_UIO 1
/* Have Windows OS */
/* #undef ZMQ_HAVE_WINDOWS */
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
#define below would cause a syntax error. */
/* #undef _UINT32_T */
/* Define to empty if `const' does not conform to ANSI C. */
/* #undef const */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
/* #undef inline */
#endif
/* Define to `unsigned int' if <sys/types.h> does not define. */
/* #undef size_t */
/* Define to `int' if <sys/types.h> does not define. */
/* #undef ssize_t */
/* Define to the type of an unsigned integer type of width exactly 32 bits if
such a type exists and the standard includes do not define it. */
/* #undef uint32_t */
/* Define to empty if the keyword `volatile' does not work. Warning: valid
code using `volatile' can become incorrect without. Disable with care. */
/* #undef volatile */
.4. then write a Android.mk file under hello-zmq/jni like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
/opt/android-toolchain/sysroot/usr/include \
LOCAL_MODULE := zeromq
LOCAL_SRC_FILES := address.cpp \
clock.cpp \
ctx.cpp \
dealer.cpp \
decoder.cpp \
devpoll.cpp \
dist.cpp \
encoder.cpp \
epoll.cpp \
err.cpp \
fq.cpp \
io_object.cpp \
io_thread.cpp \
ip.cpp \
ipc_address.cpp \
ipc_connecter.cpp \
ipc_listener.cpp \
kqueue.cpp \
lb.cpp \
mailbox.cpp \
msg.cpp \
mtrie.cpp \
object.cpp \
options.cpp \
own.cpp \
pair.cpp \
pgm_receiver.cpp \
pgm_sender.cpp \
pgm_socket.cpp \
pipe.cpp \
poll.cpp \
poller_base.cpp \
precompiled.cpp \
proxy.cpp \
pub.cpp \
pull.cpp \
push.cpp \
random.cpp \
reaper.cpp \
rep.cpp \
req.cpp \
router.cpp \
select.cpp \
session_base.cpp \
signaler.cpp \
socket_base.cpp \
stream_engine.cpp \
sub.cpp \
tcp.cpp \
tcp_address.cpp \
tcp_connecter.cpp \
tcp_listener.cpp \
thread.cpp \
trie.cpp \
v1_decoder.cpp \
v1_encoder.cpp \
xpub.cpp \
xsub.cpp \
zmq.cpp \
zmq_utils.cpp
LOCAL_CPPFLAGS += -D_REENTRANT -D_THREAD_SAFE -DZMQ_FORCE_POLL -fPIC
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := zeromq-jni
LOCAL_STATIC_LIBRARIES := zeromq
include $(BUILD_SHARED_LIBRARY)
.5. write a Application.mk under hello-zmq/jni:
APP_STL := gnustl_static
.6. make sure you have follow the http://www.zeromq.org/build:android 's General Prerequisites make-standalone-toolchain part.
.7. use ./ndk-build under hello-zmq/jni folder and a static library libzeromq.a will usable.
I have test for android device and it is just work fine.
I am still looking for a official way to build zeromq for android...

How to detect compilation by Android NDK in a C/C++ file?

Is there a preprocessor macro that will let me know NDK is compiling my code? I could manually define my own, but I'd rather not if possible.
It is #ifdef __ANDROID__ as seen by running the preprocessor:
~$ /usr/local/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -E -dM - < /dev/null | grep -i android
The output is:
#define __ANDROID__ 1
No need to depend on defining stuff in your project especially if you're skipping the NDK build system.
This is a late answer, but for completeness, here are the preprocessor definitions for android-eabi before including any header files. A C++ header will bring in a slew of additional headers.
The output below is from Detecting Android in C/C++ Source Files (Preprocessor Macros) (circa 2013) on the Android NDK mailing list. Notice __ANDROID__ is defined, but not __android__ or ANDROID.
$ arm-linux-androideabi-cpp -dM < /dev/null | sort
#define __ANDROID__ 1
#define __APCS_32__ 1
#define __ARMEL__ 1
#define __ARM_ARCH_5TE__ 1
#define __ARM_EABI__ 1
#define __ARM_FEATURE_DSP 1
#define __ARM_PCS 1
#define __BIGGEST_ALIGNMENT__ 8
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __CHAR16_TYPE__ short unsigned int
#define __CHAR32_TYPE__ unsigned int
#define __CHAR_BIT__ 8
#define __CHAR_UNSIGNED__ 1
#define __DBL_DECIMAL_DIG__ 17
#define __DBL_DENORM_MIN__ ((double)4.9406564584124654e-324L)
#define __DBL_DIG__ 15
#define __DBL_EPSILON__ ((double)2.2204460492503131e-16L)
#define __DBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __DBL_MANT_DIG__ 53
#define __DBL_MAX_10_EXP__ 308
#define __DBL_MAX_EXP__ 1024
#define __DBL_MAX__ ((double)1.7976931348623157e+308L)
#define __DBL_MIN_10_EXP__ (-307)
#define __DBL_MIN_EXP__ (-1021)
#define __DBL_MIN__ ((double)2.2250738585072014e-308L)
#define __DEC128_EPSILON__ 1E-33DL
#define __DEC128_MANT_DIG__ 34
#define __DEC128_MAX_EXP__ 6145
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __DEC128_MIN_EXP__ (-6142)
#define __DEC128_MIN__ 1E-6143DL
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __DEC32_EPSILON__ 1E-6DF
#define __DEC32_MANT_DIG__ 7
#define __DEC32_MAX_EXP__ 97
#define __DEC32_MAX__ 9.999999E96DF
#define __DEC32_MIN_EXP__ (-94)
#define __DEC32_MIN__ 1E-95DF
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC64_MANT_DIG__ 16
#define __DEC64_MAX_EXP__ 385
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __DEC64_MIN_EXP__ (-382)
#define __DEC64_MIN__ 1E-383DD
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DECIMAL_DIG__ 17
#define __DEC_EVAL_METHOD__ 2
#define __ELF__ 1
#define __FINITE_MATH_ONLY__ 0
#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __FLT_DECIMAL_DIG__ 9
#define __FLT_DENORM_MIN__ 1.4012984643248171e-45F
#define __FLT_DIG__ 6
#define __FLT_EPSILON__ 1.1920928955078125e-7F
#define __FLT_EVAL_METHOD__ 0
#define __FLT_HAS_DENORM__ 1
#define __FLT_HAS_INFINITY__ 1
#define __FLT_HAS_QUIET_NAN__ 1
#define __FLT_MANT_DIG__ 24
#define __FLT_MAX_10_EXP__ 38
#define __FLT_MAX_EXP__ 128
#define __FLT_MAX__ 3.4028234663852886e+38F
#define __FLT_MIN_10_EXP__ (-37)
#define __FLT_MIN_EXP__ (-125)
#define __FLT_MIN__ 1.1754943508222875e-38F
#define __FLT_RADIX__ 2
#define __GNUC_GNU_INLINE__ 1
#define __GNUC_MINOR__ 6
#define __GNUC_PATCHLEVEL__ 0
#define __GNUC__ 4
#define __GXX_ABI_VERSION 1002
#define __GXX_TYPEINFO_EQUALITY_INLINE 0
#define __INT16_C(c) c
#define __INT16_MAX__ 32767
#define __INT16_TYPE__ short int
#define __INT32_C(c) c
#define __INT32_MAX__ 2147483647
#define __INT32_TYPE__ int
#define __INT64_C(c) c ## LL
#define __INT64_MAX__ 9223372036854775807LL
#define __INT64_TYPE__ long long int
#define __INT8_C(c) c
#define __INT8_MAX__ 127
#define __INT8_TYPE__ signed char
#define __INTMAX_C(c) c ## LL
#define __INTMAX_MAX__ 9223372036854775807LL
#define __INTMAX_TYPE__ long long int
#define __INTPTR_MAX__ 2147483647
#define __INTPTR_TYPE__ int
#define __INT_FAST16_MAX__ 2147483647
#define __INT_FAST16_TYPE__ int
#define __INT_FAST32_MAX__ 2147483647
#define __INT_FAST32_TYPE__ int
#define __INT_FAST64_MAX__ 9223372036854775807LL
#define __INT_FAST64_TYPE__ long long int
#define __INT_FAST8_MAX__ 127
#define __INT_FAST8_TYPE__ signed char
#define __INT_LEAST16_MAX__ 32767
#define __INT_LEAST16_TYPE__ short int
#define __INT_LEAST32_MAX__ 2147483647
#define __INT_LEAST32_TYPE__ int
#define __INT_LEAST64_MAX__ 9223372036854775807LL
#define __INT_LEAST64_TYPE__ long long int
#define __INT_LEAST8_MAX__ 127
#define __INT_LEAST8_TYPE__ signed char
#define __INT_MAX__ 2147483647
#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
#define __LDBL_DIG__ 15
#define __LDBL_EPSILON__ 2.2204460492503131e-16L
#define __LDBL_HAS_DENORM__ 1
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __LDBL_MANT_DIG__ 53
#define __LDBL_MAX_10_EXP__ 308
#define __LDBL_MAX_EXP__ 1024
#define __LDBL_MAX__ 1.7976931348623157e+308L
#define __LDBL_MIN_10_EXP__ (-307)
#define __LDBL_MIN_EXP__ (-1021)
#define __LDBL_MIN__ 2.2250738585072014e-308L
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __LONG_MAX__ 2147483647L
#define __NO_INLINE__ 1
#define __ORDER_BIG_ENDIAN__ 4321
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __ORDER_PDP_ENDIAN__ 3412
#define __PIC__ 1
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __PTRDIFF_MAX__ 2147483647
#define __PTRDIFF_TYPE__ int
#define __REGISTER_PREFIX__
#define __SCHAR_MAX__ 127
#define __SHRT_MAX__ 32767
#define __SIG_ATOMIC_MAX__ 2147483647
#define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1)
#define __SIG_ATOMIC_TYPE__ int
#define __SIZEOF_DOUBLE__ 8
#define __SIZEOF_FLOAT__ 4
#define __SIZEOF_INT__ 4
#define __SIZEOF_LONG_DOUBLE__ 8
#define __SIZEOF_LONG_LONG__ 8
#define __SIZEOF_LONG__ 4
#define __SIZEOF_POINTER__ 4
#define __SIZEOF_PTRDIFF_T__ 4
#define __SIZEOF_SHORT__ 2
#define __SIZEOF_SIZE_T__ 4
#define __SIZEOF_WCHAR_T__ 4
#define __SIZEOF_WINT_T__ 4
#define __SIZE_MAX__ 4294967295U
#define __SIZE_TYPE__ unsigned int
#define __SOFTFP__ 1
#define __STDC_HOSTED__ 1
#define __STDC__ 1
#define __THUMB_INTERWORK__ 1
#define __UINT16_C(c) c
#define __UINT16_MAX__ 65535
#define __UINT16_TYPE__ short unsigned int
#define __UINT32_C(c) c ## U
#define __UINT32_MAX__ 4294967295U
#define __UINT32_TYPE__ unsigned int
#define __UINT64_C(c) c ## ULL
#define __UINT64_MAX__ 18446744073709551615ULL
#define __UINT64_TYPE__ long long unsigned int
#define __UINT8_C(c) c
#define __UINT8_MAX__ 255
#define __UINT8_TYPE__ unsigned char
#define __UINTMAX_C(c) c ## ULL
#define __UINTMAX_MAX__ 18446744073709551615ULL
#define __UINTMAX_TYPE__ long long unsigned int
#define __UINTPTR_MAX__ 4294967295U
#define __UINTPTR_TYPE__ unsigned int
#define __UINT_FAST16_MAX__ 4294967295U
#define __UINT_FAST16_TYPE__ unsigned int
#define __UINT_FAST32_MAX__ 4294967295U
#define __UINT_FAST32_TYPE__ unsigned int
#define __UINT_FAST64_MAX__ 18446744073709551615ULL
#define __UINT_FAST64_TYPE__ long long unsigned int
#define __UINT_FAST8_MAX__ 255
#define __UINT_FAST8_TYPE__ unsigned char
#define __UINT_LEAST16_MAX__ 65535
#define __UINT_LEAST16_TYPE__ short unsigned int
#define __UINT_LEAST32_MAX__ 4294967295U
#define __UINT_LEAST32_TYPE__ unsigned int
#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
#define __UINT_LEAST64_TYPE__ long long unsigned int
#define __UINT_LEAST8_MAX__ 255
#define __UINT_LEAST8_TYPE__ unsigned char
#define __USER_LABEL_PREFIX__
#define __VERSION__ "4.6 20120106 (prerelease)"
#define __VFP_FP__ 1
#define __WCHAR_MAX__ 4294967295U
#define __WCHAR_MIN__ 0U
#define __WCHAR_TYPE__ unsigned int
#define __WINT_MAX__ 4294967295U
#define __WINT_MIN__ 0U
#define __WINT_TYPE__ unsigned int
#define __arm__ 1
#define __linux 1
#define __linux__ 1
#define __pic__ 1
#define __unix 1
#define __unix__ 1
#define linux 1
#define unix 1
Short answer: #ifdef ANDROID .
The ANDROID macro is defined for you in build-module.mk (part of the standard build system):
# always define ANDROID when building binaries
#
LOCAL_CFLAGS := -DANDROID $(LOCAL_CFLAGS)

Categories

Resources