NDK 17 error: treating warnings as errors

第一种情况:

  E:/ndk/android-ndk-r17b/build//../sources/cxx-stl/llvm-libc++/include/sstream:621: warning: relocation refers to discarded section
  ././../../../src/lib_json/json_reader.cpp:625: warning: relocation refers to discarded section
  E:/ndk/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: treating warnings as errors
  clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法:
在CMakeLists.txt里加入如下一行即可解决:
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wall -v -Wl,--no-fatal-warnings")

必须是上面的这种形式,不能是以下形式
set(CMAKE_SHARED_LINKER_FLAGS " -Wall -v -Wl,--no-warn-shared-textrel")
 ,这种还是不能解决问题,需要带上${CMAKE_SHARED_LINKER_FLAGS};
相当于是增加配置参数,+=
第二种情况:

错误:

D:/android/android-ndk-r13b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: shared library text segment is not shareable

D:/android/android-ndk-r13b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: treating warnings as errors

 

在CMakeLists.txt里加入如下一行即可解决:

 

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wall -v -Wl,--no-warn-shared-textrel")

第三种情况:

在CMakeLists.txt里加入如下一行即可解决:

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wall -v -Wl,-Wno-error=format-security")

参考 :https://stackoverflow.com/questions/35950410/ndk-11-linker-is-treating-warnings-as-errors/35950411

你可能感兴趣的:(android,JNI/NDK开发)