1

I'm building a library in C with the Android NDK which links to some static libraries provided by another team. If I call a function that's defined in one of those libraries, but not declared by any of my imported headers, I get no error or warning from the compiler. It looks like the compiler assumes that the arguments I pass in are of the correct types. I don't like this, because I might call the function incorrectly and not know it.

For example, if the static library contains a function like "void MyFunc(int a, char *b);", then I expect each of the following to produce an error:

  • MyFunc();
  • MyFunc(1, 2);
  • MyFunc(1, '2', 3);

If I include a declaration of the function, then the compiler enforces that the number and types of the parameters are correct.

Is there a way to tell the NDK compiler to show an error or warning when a call is made to an undeclared function?

jason44107
  • 399
  • 2
  • 13
  • OK, I got it. In Android.mk, add "-Wimplicit-function-declaration" or "-Werror-implicit-function-declaration" to the LOCAL_CFLAGS variable. – jason44107 Jul 26 '13 at 15:38
  • 1
    It's usually good to just throw in `-Wall`, which includes `-Wimplicit-function-declaration` for C (and about 28 others). It's not actually "all" warnings, just the generally useful ones. – fadden Jul 26 '13 at 16:40

1 Answers1

0

In Android.mk, add -Wimplicit-function-declaration or -Werror-implicit-function-declaration to the LOCAL_CFLAGS variable. Or add -Wall; that's good too. (Thanks, fadden!)

jason44107
  • 399
  • 2
  • 13