Antoine Zambelli Antoine Zambelli -3 years ago 322
C++ Question

Android NDK Linker (GStreamer) - invalid linker name -fuse-ld=gold

Trying to setup GStreamer for Android using Android Studio on Windows. I'm mostly following the tutorial from their site as best I can, as well as looking at this (plus whatever I can find that helps). I get an:

Error:error: invalid linker name in argument '-fuse-ld=gold'


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := app-1.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -landroid


$(error GSTREAMER_ROOT_ANDROID is not defined!)

GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)\share\gst-android\ndk-build
GSTREAMER_PLUGINS := coreelements ogg theora vorbis videoconvert audioconvert audioresample playback glimagesink soup opensles
G_IO_MODULES := gnutls
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0


and app/build.gradle:

apply plugin: ''

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.quant.icarus"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner ""

externalNativeBuild {
ndkBuild {
def gstRoot

if (project.hasProperty('gstAndroidRoot'))
gstRoot = project.gstAndroidRoot

if (gstRoot == null)
throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your in the top level directory of the unpacked universal GStreamer Android binaries')

arguments "NDK_APPLICATION_MK=src/main/jni/", "GSTREAMER_JAVA_SRC_DIR=src/main/java", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/main/assets"

targets "app", "gstreamer_android"

// All archs except MIPS and MIPS64 are supported
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
externalNativeBuild {
ndkBuild {
path 'src/main/jni/'

afterEvaluate {
compileDebugJavaWithJavac.dependsOn 'externalNativeBuildDebug'
compileReleaseJavaWithJavac.dependsOn 'externalNativeBuildRelease'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('', {
exclude group: '', module: 'support-annotations'
compile ''
compile ''
testCompile 'junit:junit:4.12'

Gradle project sync runs without any problems. But Make Project produces the following:

Error:error: invalid linker name in argument '-fuse-ld=gold'

Or more verbose:

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process C:\Users\Quant\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\Quant\AndroidStudioProjects\Icarus\app\src\main\jni\ NDK_APPLICATION_MK=C:\Users\Quant\AndroidStudioProjects\Icarus\app\src\main\jni\ APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-23 NDK_OUT=C:/Users/Quant/AndroidStudioProjects/Icarus/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\Quant\AndroidStudioProjects\Icarus\app\build\intermediates\ndkBuild\debug\lib NDK_APPLICATION_MK=src/main/jni/ GSTREAMER_JAVA_SRC_DIR=src/main/java GSTREAMER_ROOT_ANDROID=C:\Users\Quant\Desktop\GStreamer\arm GSTREAMER_ASSETS_DIR=src/main/assets gst-build-arm64-v8a/}
GStreamer : [GEN] => gst-build-arm64-v8a/gstreamer_android.c
GStreamer : [COMPILE] => gst-build-arm64-v8a/gstreamer_android.c
GStreamer : [LINK] => gst-build-arm64-v8a/
clang.exe: error: invalid linker name in argument '-fuse-ld=gold'
make: *** [buildsharedlibrary_arm64-v8a] Error 1

Any ideas on how to fix this? I've seen some threads that say to add flags to make it gold.exe...except no one is saying where the flags are set (and the threads didn't seem all too resolved).

I replaced the 'ld.exe' file as indicated in the gstreamer install guide, even if it seemed dated (I did that after getting the same error - so that's not causing it).

Answer Source

It is a problem with the clang.exe process that tries to link together the libraries. Note, there is no need to change the ld.exe file as in the install instructions from the link in the question.

Fix: you need to change two files per architecture in the GStreamer directory so that the linker gets called as gold.exe and not gold.

For each architecture you're interested in you need to go to (using arm64 as an example):

1) path\to\Gstreamer\root\arm64\share\gst-android\ndk-build\ and change -fuse-ld=gold to -fuse-ld=gold.exe (it only appears once in the file).

Now go to:

2) path\to\Gstreamer\root\arm64\include\gmp.h and change -fuse-ld=gold to -fuse-ld=gold.exe (again, only one occurrence).

There were some minor fixes to my posted and gradle files to get things to fully compile, but that seems outside the scope of this question (added -llog to local ldlibs and used only core plugin).

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