C99 problem with logging

795 views
Skip to first unread message

Tobias

unread,
Nov 27, 2009, 9:28:51 AM11/27/09
to android-ndk
Hello,
I have been trying to make print outs in my C code and I found the
following thread for doing so:

http://groups.google.com/group/android-ndk/browse_thread/thread/d6c5e8f25f1ee543

This thread suggests that I make the following command:

#include <android/log.h>

#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "libnav",
__VA_ARGS__)


when i try to compile it I get the following error:


apps/Camera/project/jni/picture_buffer.c:22:1: warning: __VA_ARGS__
can only app
ear in the expansion of a C99 variadic macro

I also tried to call the function "__android_log_print" directly in
the following way:

__android_log_print(ANDROID_LOG_VERBOSE, "libnav", "Here Im writing a
comment")

and it didn't work eather.

Any suggestions on how to solve this issue, I'm using cygwin if that
can have anything to do with it as well.

Best regards,
Tobias Lindberg

David Turner

unread,
Nov 27, 2009, 2:16:25 PM11/27/09
to andro...@googlegroups.com
Are you trying to compile this with the NDK ? I don't think you should see this warning then.
Are you using specific compiler flags in your LOCAL_CFLAGS definition ? If so, which ones ?


--

You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.



Tobias

unread,
Nov 30, 2009, 4:33:03 AM11/30/09
to android-ndk
Hello,
yes I'm compiling this with the NDK in cygwin and I am not using any
flags in my LOCAL_CFLAGS, in fact this variable is not defined
anywhere in my code, should I define it somewhere?

On Nov 27, 8:16 pm, David Turner <di...@android.com> wrote:
> Are you trying to compile this with the NDK ? I don't think you should see
> this warning then.
> Are you using specific compiler flags in your LOCAL_CFLAGS definition ? If
> so, which ones ?
>
> On Fri, Nov 27, 2009 at 6:28 AM, Tobias <tobias.e.lindb...@gmail.com> wrote:
> > Hello,
> > I have been trying to make print outs in my C code and I found the
> > following thread for doing so:
>
> >http://groups.google.com/group/android-ndk/browse_thread/thread/d6c5e...
>
> > This thread suggests that I make the following command:
>
> > #include <android/log.h>
>
> > #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, "libnav",
> > __VA_ARGS__)
>
> > when i try to compile it I get the following error:
>
> > apps/Camera/project/jni/picture_buffer.c:22:1: warning: __VA_ARGS__
> > can only app
> > ear in the expansion of a C99 variadic macro
>
> > I also tried to call the function "__android_log_print" directly in
> > the following way:
>
> > __android_log_print(ANDROID_LOG_VERBOSE, "libnav", "Here Im writing a
> > comment")
>
> > and it didn't work eather.
>
> > Any suggestions on how to solve this issue, I'm using cygwin if that
> > can have anything to do with it as well.
>
> > Best regards,
> > Tobias Lindberg
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .

RangaRao

unread,
Dec 30, 2009, 10:42:29 AM12/30/09
to android-ndk
Hi,

I am also facing the same issue.Did this issue resolved.
Could you please let me know the solution.

below are my CFLAGS(my code uses STLPORT library hence these flags are
required)

LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \
-D__NEW__ \
-D__SGI_STL_INTERNAL_PAIR_H \
-DANDROID \
-DOS_ANDROID \
-DANDROID_NDK \
-D_STLP_NO_EXCEPTIONS

RangaRao

unread,
Dec 30, 2009, 10:50:18 AM12/30/09
to android-ndk
Adding to the previous chain.

I was succeeded in using the __android_log_print directly in my JNI
code.

But I am facing the problem when when i try to define as suggested in
this mail chain.

Please provide the suggestions to solve the issue.

Olivier Guilyardi

unread,
Dec 30, 2009, 11:24:59 AM12/30/09
to andro...@googlegroups.com
On 12/30/2009 04:50 PM, RangaRao wrote:
>
> I was succeeded in using the __android_log_print directly in my JNI
> code.
>
> But I am facing the problem when when i try to define as suggested in
> this mail chain.

You may need your macro to explicitly pass the non-variable format argument:

#define LOGV(F, ...) __android_log_print(ANDROID_LOG_VERBOSE, "libnav", F, ##
__VA_ARGS__)

I personally use the following with success. It also automatically logs the
function from which LOG() was called.

#define LOG(M, ...) _log(__func__, M, ## __VA_ARGS__)

void _log( const char *func, const char *message, ...) {
va_list arg;
va_start(arg, message);
char str[256];
vsnprintf(str, 256, message, arg);
__android_log_print(ANDROID_LOG_DEBUG, "SomeTag", "%s: %s", func, str);
va_end(arg);
}

Also, don't forget to link with liblog, eg:
LOCAL_LDLIBS := -llog

Hope that helps

--
Olivier


RangaRao

unread,
Jan 1, 2010, 12:46:30 AM1/1/10
to android-ndk
Thank you Oliver.
It worked.

Olivier Guilyardi

unread,
Jan 1, 2010, 10:26:43 AM1/1/10
to andro...@googlegroups.com
Good

If you happen to use my LOG() macro and _log() function, then you should also
instruct gcc to check the format and variable arguments with:

void _log(const char *func, const char *message, ...)
__attribute__ ((format (printf, 2, 3)));

Olivier

> --
>
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.

> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages