5

So I'm attempting to use libopus on my native code for an Android application. My Android.mk file looks like this:

PLATFORM_PREFIX := /opt/android-ext/ LOCAL_PATH := $(PLATFORM_PREFIX)/lib include $(CLEAR_VARS) LOCAL_MODULE := libopus LOCAL_SRC_FILES := libopus.a include $(PREBUILT_STATIC_LIBRARY) # I have to redeclare LOCAL_PATH because the library is in /opt/android-ext/ # and my project is somewhere else. Not very elegant. LOCAL_PATH := /home/sergio/workspace/Project/jni include $(CLEAR_VARS) LOCAL_MODULE := opusUtilsNative LOCAL_SRC_FILES := opusUtilsNative.c LOCAL_C_INCLUDES += $(PLATFORM_PREFIX)/include LOCAL_STATIC_LIBRARIES := android_native_app_glue libopus include $(BUILD_SHARED_LIBRARY) 

And my code in opusUtilsNative.c looks like this:

#include "opusUtilsNative.h" #include <opus/opus.h> #include <opus/opus_types.h> JNIEXPORT jbyteArray JNICALL Java_Project_OpusUtils_encode (JNIEnv * je, jclass jc, jbyteArray data){ int rc; opus_int16 * testOutBuffer; unsigned char* opusBuffer; OpusDecoder *dec; dec = opus_decoder_create(48000, 2, &rc); return data; } 

And when I try to build it, it works fine only if I remove the line that uses the "opus_decoder_create" function. Else I will get this:

error: undefined reference to 'opus_decoder_create' 

I can see that opus_decoder_create is clearly defined on opus.h, which is clearly being included since if I exclude that line, I'll get an error regarding the opus_int16 and OpusDecoder declarations. How come some definitions are being included and some aren't?

Any help will be greatly appreciated.

3 Answers 3

5

This was tricky. After digging around for a bit, I realized I hadn't cross-compiled the opus library correctly, and I didn't have an ARM binary after all.

A good way to verify if your library was cross-compiled correctly:

cd /opt/android-ext/lib #Or wherever the .a file is ar x libopus.a file tables_LTP.o #Or any of the .o files generated by ar x 

The output should look like this:

tables_LTP.o: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped 

Otherwise, you might want to double-check your cross-compilation process.

Sign up to request clarification or add additional context in comments.

1 Comment

Do you perhaps also know how to compile it cross-platform on Windows? I am experiencing the same error as you, but I am using Visual Studio 2015 + Cross-Platform Tools and clang and NDK.
0

It's error from linker, not from compiler. You forgot to add reference to correspondent libraries to your Android.mk file, do smth like this:

LOCAL_LDLIBS += -lopus 

Comments

0

I forgot to integrate one key library

LOCAL_LDLIBS := -lGLESv2

This fixed my problem.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.