C API for logging to logcat

huangapple go评论50阅读模式
英文:

C API for logging to logcat

问题

如果我有一个使用Android NDK编译的用C编写的ELF二进制文件,是否有一个用于记录消息以便它们出现在logcat中的API?

英文:

If I have an ELF binary written in C and compiled using an Android NDK, is there an API for logging messages so that they show up in logcat?

答案1

得分: 2

是的。 这可以通过包含以下方式完成

#include <android/log.h>

并调用

int __android_log_print(
  int prio,
  const char *tag,
  const char *fmt,
  ...
);

甚至可以通过以下方式设置默认标签

void __android_log_set_default_tag(
  const char *tag
);

这样,您可以在__android_log_print中将NULL作为标签。

您需要将-llog添加到您的链接器标志中。

英文:

Yes. This can be done by including

#include <android/log.h>

and calling

int __android_log_print(
  int prio,
  const char *tag,
  const char *fmt,
  ...
);

You can even set the default tag via

void __android_log_set_default_tag(
  const char *tag
);

This way, you can pull NULL as the tag in __android_log_print.

You'll have to add -llog to your linker flags.

huangapple
  • 本文由 发表于 2023年2月7日 04:00:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75368084.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定