Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 -Wl,--fatal-warnings is being passed to the linker. I've tried adding LOCAL_LDFLAGS:=-Wl,--no-fatal-warnings to my Android.mk file, and I can see in the linker output that it is in fact being passed to the linker, but it is passed before -Wl,--fatal-warnings, 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?

like image 408
Jordan Avatar asked Mar 11 '16 21:03

Jordan


1 Answers

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 build-binary.mk, 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.
ifneq ($(LOCAL_DISABLE_FATAL_LINKER_WARNINGS),true)
  LOCAL_LDFLAGS += -Wl,--fatal-warnings
endif

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.

like image 115
Jordan Avatar answered Nov 15 '22 19:11

Jordan