为什么创建so文件时不能创建.c .cpp文件?

时间:2019-09-06 03:25:49

标签: android-ndk

使用下面的Android.mk文件进行构建时,发生错误。我想知道是否无法通过将.c和.cpp绑定到LOCAL_SRC_FILES来创建so文件?

Android.mk
     ========

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libdecoder
LOCAL_SRC_FILES := Decoder.c ima_adpcm.c Interface.c \
                   hevcWrapper.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/ \
                    $(LOCAL_PATH)/../ffmpeg/libavcodec \
                    $(LOCAL_PATH)/../ffmpeg/libavformat \
                    $(LOCAL_PATH)/../ffmpeg/libswscale

LOCAL_LDLIBS := -lz -ljnigraphics -llog
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
LOCAL_C_INCLUDES := D:/NDKandSDK_NEW/myToolChain/arm64/sysroot/usr/include $(LOCAL_C_INCLUDES)
LOCAL_LDLIBS += -Wl
else
LOCAL_C_INCLUDES := D:/NDKandSDK_NEW/myToolChain/arm/sysroot/usr/include $(LOCAL_C_INCLUDES)
LOCAL_LDLIBS += -Wl,--no-warn-shared-textrel
endif
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_CFLAGS := $(COMMON_CFLAGS) -fPIC
LOCAL_STATIC_LIBRARIES := libavformat libavcodec libswscale libavutil cpufeatures libswresample
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/cpufeatures)

================================================ =====

[system.err]#include <version>
[system.err]^~~~~~~~~
[system.err]<VERSION>
[system.err]In file included from jni/Decoder/hevcWrapper.cpp:2:
[system.err]In file included from jni/Decoder/hevcParser/HevcParserImpl.h:9:
[system.err]In file included from D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\map:481:
[system.err] In file included from D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\__node_handle:16:
[system.err] In file included from D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\optional:159:
[system.err] jni/Decoder/../ffmpeg\version:1:1: error: expected unqualified-id


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libdecoder
LOCAL_SRC_FILES := Decoder.c ima_adpcm.c Interface.c \
                  hevcWrapper.cpp \
                  hevcParser/BitstreamReader.cpp \
                  hevcParser/Hevc.cpp \
                  hevcParser/HevcParser.cpp \
                  hevcParser/HevcParserImpl.cpp \
                  hevcParser/HevcUtils.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/ \
                    $(LOCAL_PATH)/../ffmpeg/libavcodec \
                    $(LOCAL_PATH)/../ffmpeg/libavformat \
                    $(LOCAL_PATH)/../ffmpeg/libswscale

LOCAL_LDLIBS := -lz -ljnigraphics -llog

ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
LOCAL_C_INCLUDES := D:/NDKandSDK_NEW/myToolChain/arm64/sysroot/usr/include $(LOCAL_C_INCLUDES)
LOCAL_LDLIBS += -Wl
else
LOCAL_C_INCLUDES := D:/NDKandSDK_NEW/myToolChain/arm/sysroot/usr/include $(LOCAL_C_INCLUDES)
LOCAL_LDLIBS += -Wl,--no-warn-shared-textrel
endif
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_CFLAGS := $(COMMON_CFLAGS) -fPIC
LOCAL_CPPFLAGS += -fPIC -std=c++11
LOCAL_STATIC_LIBRARIES := libavformat libavcodec libswscale libavutil cpufeatures libswresample
LOCAL_ARM_MODE := arm

[system.err] 4.2
[system.err] ^
[system.err] In file included from jni/Decoder/hevcWrapper.cpp:2:
[system.err] In file included from jni/Decoder/hevcParser/HevcParserImpl.h:9:
[system.err] D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\map:488:10: warning: non-portable path to file '<VERSION>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
[system.err] #include <version>
[system.err] ^~~~~~~~~
[system.err]<VERSION>
[system.err] In file included from jni/Decoder/hevcWrapper.cpp:2:
[system.err] In file included from jni/Decoder/hevcParser/HevcParserImpl.h:9:
[system.err] In file included from D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\map:488:
[system.err] jni/Decoder/../ffmpeg\version:1:1: error: expected unqualified-id
[system.err] 4.2
[system.err] ^
[system.err] In file included from jni/Decoder/hevcWrapper.cpp:2:
[system.err] In file included from jni/Decoder/hevcParser/HevcParserImpl.h:10:
[system.err] D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\list:189:10: warning: non-portable path to file '<VERSION>'; specified path differs in case from file name on disk [-Wnonportable-include-path]
[system.err] #include <version>
[system.err]^~~~~~~~~
[system.err]<VERSION>
[system.err] In file included from jni/Decoder/hevcWrapper.cpp:2:
[system.err] In file included from jni/Decoder/hevcParser/HevcParserImpl.h:10:
[system.err] In file included from D:/NDKandSDK_NEW/Android/Sdk/ndk-bundle/build//../sources/cxx-stl/llvm-libc++/include\list:189
[system.err]jni/Decoder/../ffmpeg\version:1:1: error: expected unqualified 
[system.err]4.2
[system.err]^
[system.err]jni/Decoder/hevcWrapper.cpp:4:46: error: brackets are not allowed here; to declare an array, place the brackets after the name

1 个答案:

答案 0 :(得分:0)

那是ffmpeg或您的Android.mk中的错误:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/ 

您要将ffmpeg源树的根添加到此处的包含路径中。

[system.err] jni/Decoder/../ffmpeg\version:1:1: error: expected unqualified-id

该目录包含一个名为“版本”的文件,该文件与C ++标准库头冲突:https://en.cppreference.com/w/cpp/header/version

如果该目录不需要位于包含路径中,请不要将其添加到LOCAL_C_INCLUDES中。这不是我见过的第一个解决此问题的项目(这也是jsoncpp的问题),在这种情况下,实际上是必需的包含目录。如果是这种情况,那么您需要删除或重命名名为version的文件,因为它不能出现在C ++项目中(此标头是C ++ 20以来的新名称,但是所有C ++库标头都包含该标头)。