【问题标题】:Linker command failed with exit code 1 when building ffmpeg static libraries构建 ffmpeg 静态库时,链接器命令失败,退出代码为 1
【发布时间】:2017-11-09 18:20:50
【问题描述】:

我正在尝试构建 ffmpeg 静态库并将它们链接到 android 项目以实现视频播放器。目标是使播放器能够从类似于 p2p 文件共享网络的各种来源接收视频文件。 (目标 api 是 21 级,比使用 MediaSource 的官方解决方案少 1 级)

我设法编译了ffmpeg from this repo(所有代码都按原样使用),但后来我遇到了链接问题。每当我尝试编译时,我都会得到在我的代码中调用的 ffmpeg 方法列表和一个简短的雄辩消息:

链接器命令失败,退出代码为 1

我不知道如何将 -v 标志传递给 android studio 中的链接器。如果有人暗示我,那就太好了。

我使用 android studio,使用 gradle 和 cmake 构建。

这是我的文件: build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(模块)

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        productFlavors {
            x86 {
                ndk {
                    abiFilter "x86"
                }
            }
            arm {
                ndk {
                    abiFilters "armeabi-v7a"
                }
            }
            armv7 {
                ndk {
                    abiFilters "armeabi-v7a"
                }
            }
        }
        defaultConfig {
            applicationId "com.example.ledo.ndkapplication"
            minSdkVersion 22
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++11 -frtti -fexceptions"
                    arguments '-DANDROID_PLATFORM=android-16'
                }
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
        splits {
            abi {
                enable true
                reset()
                include 'x86', 'armeabi-v7a'
                universalApk true
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.android.support:design:25.3.1'
        compile 'com.writingminds:FFmpegAndroid:0.3.2'
        testCompile 'junit:junit:4.12'
    }

CMakeLists.txt

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 2.8)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp
             src/main/cpp/NativePlayer.h
             src/main/cpp/NativePlayer.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
find_library(png-lib png)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

#avcodec
#avfilter
#avformat
#avutil
#swresample
#swscale

#${ANDROID_ABI}

message(${ANDROID_ABI})
set(FFMPEG_ROOT_DIR src/main/libs/ffmpeg/${ANDROID_ABI})

add_library(avcodec STATIC IMPORTED)
add_library(avformat STATIC IMPORTED)
add_library(avfilter STATIC IMPORTED)
add_library(avutil STATIC IMPORTED)
add_library(swresample STATIC IMPORTED)
add_library(swscale STATIC IMPORTED)

#SET_TARGET_PROPERTIES(avcodec PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavcodec.a)
#SET_TARGET_PROPERTIES(avfilter PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avfilter PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavfilter.a)
#SET_TARGET_PROPERTIES(avformat PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavformat.a)
#SET_TARGET_PROPERTIES(avutil PROPERTIES LINKER_LANGUAGE C)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libavutil.a)
#SET_TARGET_PROPERTIES(swresample PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswresample.a)
#SET_TARGET_PROPERTIES(swscale PROPERTIES LINKER_LANGUAGE C)
set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib/libswscale.a)

include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/include )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${FFMPEG_ROOT_DIR}/lib )
target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                       avcodec
                       avformat
                       #avfilter
                       #swresample
                       #swscale
                       #avutil
                       GLESv2)

我在以下位置有 .a 文件:

  • %PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a
  • %PROJECT_DIR%/app/src/libs/ffmpeg/armeabi-v7a-neon
  • %PROJECT_DIR%/app/src/libs/ffmpeg/x86

在我看来,链接器本身并没有丢失文件。 (如果我放错了位置,我会得到不同的输出。)

【问题讨论】:

    标签: android android-studio ffmpeg android-ndk linker-errors


    【解决方案1】:

    错误“Linker command failed with exit code 1”通常后面跟着更详细的错误。要查找更多详细信息,请在 Xcode 中单击 Buildtime 下的错误并选择 Reveal in log。这应该会给你额外的提示。如果没有任何具体错误,就不可能知道问题出在哪里。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 2018-11-03
      • 2015-08-06
      相关资源
      最近更新 更多