Jordan Bondo Jordan Bondo - 1 year ago 186
Android Question

NDK 11 linker is treating warnings as errors

I'm trying to build a library with android ndk-11 and I'm getting a linker error:

arm-linux-androideabi/bin/ld: error: treating warnings as errors

I do not get this error if I use ndk-r10e.

Running ndk-build with V=1, I see that
is being passed to the linker. I've tried adding
to my file, and I can see in the linker output that it is in fact being passed to the linker, but it is passed before
, so it is being ignored.

The warnings are coming from a 3rd party library, so I can't just recompile it to fix the warnings (they are all 'relocation refers to discarded section' warnings). I've always seen these warnings and have never had any problems.

Does anyone know how to tell the ndk-11 linker not to treat warnings as errors?

Answer Source

I figured this out as I was writing it, so I thought I'd share the solution.

<NDK_ROOT>/build/core has a bunch of .mk files that are used when running ndk-build. Inside, there are a few new (undocumented) checks for variables you can define. For this particular one, there is the following block:

# We enable fatal linker warnings by default.
# If LOCAL_DISABLE_FATAL_LINKER_WARNINGS is true, we don't enable this check.
  LOCAL_LDFLAGS += -Wl,--fatal-warnings

Adding LOCAL_DISABLE_FATAL_LINKER_WARNINGS=true to my .mk file made the error go away.

There are lots of other things defined in these files, so if you're getting weird build errors all of a sudden, take a look in there to see if something new has been enabled.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download