Question

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?

Was it helpful?

Solution

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!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top