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;
Related
I have a problem with this:
C code
#define CREATE_HTML_FILE_SCRIPT "/bin/curl https://coinmarketcap.com/it/currencies/bytecoin-bcn/ > /data/data/com.example.bytecoin/bcn.html"
#define CREATE_TEMP_FILE_SCRIPT "/data/local/lynx /data/data/com.example.bytecoin/bcn.html -dump > /data/data/com.example.bytecoin/bcn.txt"
system(CREATE_HTML_FILE_SCRIPT);
system(CREATE_TEMP_FILE_SCRIPT);
If I run from adb shell these commands all works well but when these command are executed from the app, file.html and file.txt are empty... I don't understand why and how I can solve it.
Well, lynx is an interactive program, so I think you'll run in trouble when using it from a system() call. But not with curl:
/* pru_curl-1.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cmd = "curl https://www.google.com/";
system(cmd); /* you will get the output of curl on stdout */
exit(EXIT_SUCCESS);
}
This is with curl redirecting its output in the shell call with the > operator:
/* pru_curl-2.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cmd = "curl https://www.google.com/ >output_file-2";
/* you will get the output of curl on output_file-2 */
system(cmd);
exit(EXIT_SUCCESS);
}
Curl, on the other side, allows you to specify -o output_file.txt and you'll be able to read the file, once the program has finished.
/* pru_curl-3.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cmd = "curl https://www.google.com/ -o output_file-3";
/* you will get the output of curl on output_file-3 */
system(cmd);
exit(EXIT_SUCCESS);
}
You have a third alternative, which is using popen(3), that allows you to start the program as a subcommand, and read the output of that program from the FILE * descriptor you get from popen(3). You could use it like this (processing character by character):
/* pru_curl-4.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cmd = "curl https://www.google.com/";
FILE *f = popen(cmd, "r");
if (!f) {
fprintf(stderr, "%s: %s\n",
cmd, strerror(errno));
exit(EXIT_FAILURE);
}
int c;
while((c = fgetc(f)) != EOF) {
printf("[%d]", c); /* you will get the downloaded file as
* sequences of numbers (the character
* values) embedded in square brackets on
* stdout */
}
pclose(f);
exit(EXIT_SUCCESS);
}
or (processing line by line):
/* pru_curl-5.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *cmd = "curl https://www.google.com/";
FILE *f = popen(cmd, "r");
if (!f) {
fprintf(stderr, "%s: %s\n",
cmd, strerror(errno));
exit(EXIT_FAILURE);
}
char line[256];
while (fgets(line, sizeof line, f)) {
/* you'll get your output in chunks of one line, or 256 bytes
* ---if longer---, encapsulated by a pair of square brackets
* drawn in a different color (gren, by the escape sequences
* used) */
fprintf(stderr,
"\033[1;33m[\033[m%s\033[32m]\033[m",
line);
}
pclose(f);
exit(EXIT_SUCCESS);
}
or (by blocks):
/* pru_curl-6.c */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 8 /* blocks in buffer */
#define CPB 11 /* chars per block */
int main()
{
char *cmd = "curl https://www.google.com/";
FILE *f = popen(cmd, "r");
if (!f) {
fprintf(stderr, "%s: %s\n",
cmd, strerror(errno));
exit(EXIT_FAILURE);
}
char block[N][CPB];
int n;
char *sep = "";
do {
/* print a blanck line between groups */
printf("%s", sep);
sep = "\n";
/* we read as many CPB byte blocks as possible to fill the
* N registers in buffer.
* Then we start again until we don't fill completely the
* buffer. */
n = fread(block, sizeof block[0], N, f);
int i;
for (i = 0; i < n; i++) {
printf("[%.*s]\n", (int)sizeof block[i], block[i]);
}
printf("finished one loop of %d blocks of %d chars, each.\n",
N, (int) sizeof block[0]);
} while (n == N);
/* n < N, so we are finished, check that probably the last register is
* not printed because it was not complete. */
pclose(f);
exit(EXIT_SUCCESS);
}
(All these examples are complete and have been tested before posting)
Edit
I have completed the code for the six programs and now all of them are executables with just building with:
$ cc pru_curl-<i>.c -o pru_curl-<i> # <i> is the program number
$ _
In each case, you can execute the program by just running:
$ pru_curl-<i>
.... <-- a lot of output (or to a file) about the contents of the root page of google.
$ _
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.
I have Java classes being translated to Objective C (J2Objc using the cradle plugin). The simple Android app and Unit tests work fine. The same simple Objective C iOS app also works perfectly. However, when I try to write similar code in a Swift project I cannot access instance variables, find methods, etc. This is relatively new to me so I may be missing something basic.
Here's the code in Objective C. Works perfectly:
SHRRefreshAppointments *mTest = [[SHRRefreshAppointments alloc] initWithId:nil withBoolean:true];
[mTest run];
SHREventListResp *mResp = [SHREventListResp parseFromWithByteArray:mTest->mResponseData_];
NSLog(#"%#", mResp.description);
Same code in Swift - I cannot find the instance variable mResponseData which is readily available in Objective C:
let mTest : SHRRefreshAppointments = SHRRefreshAppointments(id: nil, withBoolean: true)
mTest.run()
var mResp : SHREventListResp = SHREventListResp.parseFromWithByteArray(mTest.)
Here are the contents of the bridging header:
#include "JreEmulation.h"
#include "J2ObjC_header.h"
#import "com/gcatconsult/shared/remote/AppConstants.h"
#import "com/gcatconsult/shared/remote/AppUtils.h"
#import "com/gcatconsult/shared/messages/nano/Resp.h"
#import "com/gcatconsult/shared/messages/nano//Req.h"
#import "com/gcatconsult/shared/messages/nano/EventListResp.h"
#import "com/gcatconsult/shared/messages/nano/EventListReq.h"
#import "com/gcatconsult/shared/messages/nano/Event.h"
#import "com/gcatconsult/shared/remote/RefreshAppointments.h"
#import "com/gcatconsult/shared/remote/NetworkBase.h"
SHRRefreshAppointments header:
//
// Generated by the J2ObjC translator. DO NOT EDIT!
// source: /Users/gabrielchoza/AndroidStudioProjects/GcatMobile/shared/src/main/java/com/gcatconsult/shared/remote/RefreshAppointments.java
//
#include "J2ObjC_header.h"
#pragma push_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments")
#ifdef RESTRICT_ComGcatconsultSharedRemoteRefreshAppointments
#define INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments 0
#else
#define INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments 1
#endif
#undef RESTRICT_ComGcatconsultSharedRemoteRefreshAppointments
#if !defined (SHRRefreshAppointments_) && (INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments || defined(INCLUDE_SHRRefreshAppointments))
#define SHRRefreshAppointments_
#define RESTRICT_ComGcatconsultSharedRemoteNetworkBase 1
#define INCLUDE_SHRNetworkBase 1
#include "com/gcatconsult/shared/remote/NetworkBase.h"
#define RESTRICT_JavaLangRunnable 1
#define INCLUDE_JavaLangRunnable 1
#include "java/lang/Runnable.h"
#interface SHRRefreshAppointments : SHRNetworkBase < JavaLangRunnable >
#pragma mark Public
- (instancetype)initWithId:(id)requestData
withBoolean:(jboolean)asyncCall;
#pragma mark Protected
- (void)postProcessExcecute;
#end
J2OBJC_EMPTY_STATIC_INIT(SHRRefreshAppointments)
FOUNDATION_EXPORT void SHRRefreshAppointments_initWithId_withBoolean_(SHRRefreshAppointments *self, id requestData, jboolean asyncCall);
FOUNDATION_EXPORT SHRRefreshAppointments *new_SHRRefreshAppointments_initWithId_withBoolean_(id requestData, jboolean asyncCall) NS_RETURNS_RETAINED;
FOUNDATION_EXPORT SHRRefreshAppointments *create_SHRRefreshAppointments_initWithId_withBoolean_(id requestData, jboolean asyncCall);
J2OBJC_TYPE_LITERAL_HEADER(SHRRefreshAppointments)
#compatibility_alias ComGcatconsultSharedRemoteRefreshAppointments SHRRefreshAppointments;
#endif
#pragma pop_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteRefreshAppointments")
The SHRNetworkBase superclass:
//
// Generated by the J2ObjC translator. DO NOT EDIT!
// source: /Users/gabrielchoza/AndroidStudioProjects/GcatMobile/shared/src/main/java/com/gcatconsult/shared/remote/NetworkBase.java
//
#include "J2ObjC_header.h"
#pragma push_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase")
#ifdef RESTRICT_ComGcatconsultSharedRemoteNetworkBase
#define INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase 0
#else
#define INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase 1
#endif
#undef RESTRICT_ComGcatconsultSharedRemoteNetworkBase
#if !defined (SHRNetworkBase_) && (INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase || defined(INCLUDE_SHRNetworkBase))
#define SHRNetworkBase_
#define RESTRICT_JavaLangRunnable 1
#define INCLUDE_JavaLangRunnable 1
#include "java/lang/Runnable.h"
#class IOSByteArray;
#class JavaLangInteger;
#interface SHRNetworkBase : NSObject < JavaLangRunnable > {
#public
NSString *mGetPatientPath_;
NSString *mStringURL_;
IOSByteArray *mRequestData_;
IOSByteArray *mResponseData_;
jboolean mShouldCompress_;
jint mCurrentCall_;
jboolean mAsyncCall_;
}
#pragma mark Public
- (instancetype)initWithNSString:(NSString *)callPath
withBoolean:(jboolean)shouldCompress
withJavaLangInteger:(JavaLangInteger *)currentCall
withBoolean:(jboolean)async;
- (void)run;
#pragma mark Protected
- (void)postProcessExcecute;
- (id)sendAsyncServerRequestWithNSString:(NSString *)stringURL
withId:(id)requestData
withBoolean:(jboolean)shouldCompress
withJavaLangInteger:(JavaLangInteger *)currentCall;
#end
J2OBJC_EMPTY_STATIC_INIT(SHRNetworkBase)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mGetPatientPath_, NSString *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mStringURL_, NSString *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mRequestData_, IOSByteArray *)
J2OBJC_FIELD_SETTER(SHRNetworkBase, mResponseData_, IOSByteArray *)
FOUNDATION_EXPORT void SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(SHRNetworkBase *self, NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async);
FOUNDATION_EXPORT SHRNetworkBase *new_SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async) NS_RETURNS_RETAINED;
FOUNDATION_EXPORT SHRNetworkBase *create_SHRNetworkBase_initWithNSString_withBoolean_withJavaLangInteger_withBoolean_(NSString *callPath, jboolean shouldCompress, JavaLangInteger *currentCall, jboolean async);
J2OBJC_TYPE_LITERAL_HEADER(SHRNetworkBase)
#compatibility_alias ComGcatconsultSharedRemoteNetworkBase SHRNetworkBase;
#endif
#pragma pop_macro("INCLUDE_ALL_ComGcatconsultSharedRemoteNetworkBase")
Any help will be appreciated.
My limited understanding is that Swift imports Objective C properties as fields, not the fields themselves. You'll therefore need an accessor method for mResponseData.
The good news is that j2objc has a Property annotation, which you can add to the mResponseDate field so an equivalent Objective C property is generated during translation. That property should be imported later in Swift.
The Property annotation will also generate default accessors (like #synthesize does in Objective C), so if your Java class already has accessors, specify them using the getter= and setter= #property attributes. The translator's testProperties() test demonstrates a complex property annotation example.
mResponseData_ is an ivar and Swift can only access objective-c properties or functions. Alternative you can use mTest.valueForKey("mResponseData_") and mTest.setValue(someValue, forKey: "mResponseData_") or edit the generated class and transform the ivar in a property or method.
Not that you can create extension files with computed get and set to encapsulate the valueForKey implementation.
You can refer to this question for more details.
I set up logging with C++ in Android NDK.
I can print a message to logcat like this:
__android_log_write(ANDROID_LOG_INFO, "tag here", "message here");
Now let's say I have an integer called testint. How can I print the value of this int?
Something like this prints the address, but I want the value. I haven't found anything in C++ on how to do this. Thanks for any help!
__android_log_print(ANDROID_LOG_INFO, "sometag", "%p", *test);
Here's the most concise way I've seen:
#include <android/log.h>
#define LOG_TAG "someTag"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
...
// Now you can log very simply like this:
int foo = 42;
LOGD( "This is a number from JNI: %d", foo );
Also, make sure you link to the log library in your Android.mk:
LOCAL_LDLIBS := -llog
You could use __android_log_print which uses a sprintf-like syntax that formats your data into a string.
__android_log_print(ANDROID_LOG_INFO, "sometag", "test int = %d", testInt);
Take advantage of the variadic log print function you have available. For my own code, I provide a LogInfo() function to make it simple. Of course there are several options available to you here.
void LogInfo(const char *sTag, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__android_log_vprint(ANDROID_LOG_INFO, sTag, fmt, ap);
va_end(ap);
}
__android_log_print() takes a format string and a variable argument list. The format specifier you're looking for to print out a signed integer is "%d". So something like this is what you want:
int foo = 42;
__android_log_print(ANDROID_LOG_INFO, "SomeTag", "foo is %d", foo);
For more information on format strings, you can see the sprintf manual.
I trying to use va_start and va_end functions in my project, but eclipse don't want to resolve it as functions. gcc compiles whole project without errors...
[myfile.cpp]
#include <stdio.h>
#include <stdarg.h>
[...]
inline void ShowDbgMsg( const char* str, ... )
{
va_list argptr;
va_start(argptr, str);
vprintf(str, argptr);
va_end(argptr);
}
[...]
[Android.mk]
[...]
LOCAL_C_INCLUDES := jni/pvrTools/ jni/igel/ $(STLPORT_BASE)/stlport
[...]
Eclipse says:
[...]
Description Resource Path Location Type
Function 'va_start' could not be resolved igel.comdef.h /NativeProject/jni/igel line 195 Semantic Error
Function 'va_end' could not be resolved igel.comdef.h /NativeProject/jni/igel line 203 Semantic Error
Function 'va_start' could not be resolved igel.string.h /NativeProject/jni/igel line 341 Semantic Error
Function 'va_end' could not be resolved igel.string.h /NativeProject/jni/igel line 351 Semantic Error
[...]
So, it looks like Eclipse unable to locate something... How to solve this issue?
Thanks in advance!
P.S.> Project->Index->Rebuild didn't help. :(
My solution is also not pretty. But after you've deleted the error markers 100 times, try putting this code somewhere before you include stdlib.h. Then define ECLIPSEBUILD=1 in Project::Properties::C++ General::Paths and Symbols.
#if ECLIPSEBUILD // this part is just to fix spurious Eclipse errors
typedef __builtin_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L || defined(__GXX_EXPERIMENTAL_CXX0X__)
#define va_copy(d,s) __builtin_va_copy(d,s)
#endif
#define __va_copy(d,s) __builtin_va_copy(d,s)
typedef __builtin_va_list __gnuc_va_list;
typedef __gnuc_va_list va_list;
typedef va_list __va_list;
#endif
I solve this issue by replacing my va_* code with embedded compiler features:
#ifdef IGEL_PLATFORM_ANDROID
# define ShowDbgMsg(...) ((void)__android_log_print(ANDROID_LOG_INFO, "igel-debug", __VA_ARGS__))
#else
inline void ShowDbgMsg( const char* str, ... )
{
va_list argptr;
va_start(argptr, str);
vprintf(str, argptr);
va_end(argptr);
}
#endif // IGEL_PLATFORM_ANDROID
I know it's not a good solution, but it works.
#include <stdarg.h> // includes va_list
inline void ShowDbgMsg(char* format, ...)
{
va_list ap;
va_start( ap, format );
// replace vfprintf( stderr, format, ap ) with:
__android_log_vprint(0, __FILE__, format, ap);
va_end( ap );
}