How to link static library in android project

Hi,
I’m trying to include libsndfile in my android project but I get an error on linking. I tried to add the PROJECT_LDFLAGS= -lsndfile and copy the .a in the /bin/libs dir with no luck
I’m using OF V.0.8.3 on linux/debian

Someone can point me please to the right procedure to link a static library in OF Android project?

thanks in advance
husk

you also need to add the path to the library like:

PROJECT_LDFLAGS= -lsndfile -L$(PROJECT_ROOT)/bin/libs

or just add the full name of the library like:

PROJECT_LDFLAGS= $(PROJECT_ROOT)/bin/libs/libsndfile.a

Hi Arturo,
thanks for your help.
PROJECT_LDFLAGS flag worked perfectly, but now I get a new error:

error: ./bin/libs/libsndfile.a(sndfile.o): incompatible target	

I understand that this is related with the android target version used to compile the library and OF android project itself: both use same versions (API 14) and I don’t really know what’s the problem could be now.
Any hint is really apreciated
cheers
husk

don’t think is related to the api target, when are you getting that error? compiling? perhaps you compiled the library for a different platform?

Hey @arturo, I get the error during compilation, actually when I try to compile a puredata external, together with ofxPd, that has lib sndfile as dependency

sndfile.a is compiled for armeabi, compiled by myself, so I would say is the right platform (android arm).
Maybe I should use the LDFLAGS (adding sndfile) directly in ofxPd addon? Does it make any difference?

it shouldn’t except perhaps for the link order but you shouldn’t be getting this kind of message then.

is this the only error that you are getting, perhaps there’s more info in the output of the compiler that might be helpful.

Seems to me it is the only error (apart an undefined reference due to linking error)
I copy here the console output:

**** Build of configuration Release for project androidAudioExample ****

make Release PLATFORM_OS=Android 
Compiling OF library for Release
make[1]: Entering directory '/home/husk/src/of/of_v0.8.3_android_release/libs/openFrameworksCompiled/project'
make[2]: Nothing to be done for 'ReleaseABI'.
make[2]: Nothing to be done for 'ReleaseABI'.
make[2]: Nothing to be done for 'ReleaseABI'.
make[2]: Nothing to be done for 'ReleaseABI'.

Done!
make[1]: Leaving directory '/home/husk/src/of/of_v0.8.3_android_release/libs/openFrameworksCompiled/project'


Compiling androidAudioExample for Release
make[1]: Entering directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Nothing to be done for 'ReleaseABI'.
make[1]: Leaving directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Entering directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Nothing to be done for 'ReleaseABI'.
make[1]: Leaving directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Entering directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Nothing to be done for 'ReleaseABI'.
make[1]: Leaving directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
make[1]: Entering directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
Linking libs/x86/libOFAndroidApp.so for android/x86
/home/husk/src/android-ndk-r9b/toolchains/x86-4.8/prebuilt/linux-x86/bin/i686-linux-android-g++ -o libs/x86/libOFAndroidApp.so obj/android/x86/Release/src/ofApp.o obj/android/x86/Release/src/AppCore.o obj/android/x86/Release/src/main.o  ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidGPS.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidLogChannel.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidSoundPlayer.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidAccelerometer.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidUtils.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofAppAndroidWindow.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidVideoPlayer.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidSoundStream.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidVideoGrabber.o ../../../addons/obj/android/x86/Release/ofxAndroid/src/ofxAndroidVibrator.o ../../../addons/obj/android/x86/Release/ofxAccelerometer/src/ofxAccelerometer.o ../../../addons/obj/android/x86/Release/ofxPd/src/ofxPd.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/cpp/PdBase.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/cpp/PdTypes.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/libpd_wrapper/z_libpd.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/libpd_wrapper/x_libpdreceive.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/libpd_wrapper/s_libpdmidi.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/libpd_wrapper/util/z_print_util.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_vumeter.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_sched.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_vdial.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_utf8.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_dac.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_fft.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_scalar.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_glob.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_atom.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_io.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_pd.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_all_guis.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_numbox.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_template.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_path.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_array.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_hdial.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_hslider.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_math.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_arithmetic.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_arithmetic.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_obj.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_resample.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_memory.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_filter.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_bang.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_fft_mayer.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_net.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_guiconnect.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_ugen.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_conf.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_audio_dummy.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_canvas.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_misc.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_global.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_binbuf.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_array.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_midi.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_print.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_ctl.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_acoustics.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_readwrite.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_fftroutine.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_mycanvas.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_graph.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_loader.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_toggle.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_time.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_rtext.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_text.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_main.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_misc.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_traversal.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_file.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_soundfile.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_interface.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/m_class.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_osc.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_editor.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_qlist.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_audio.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/s_inter.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/d_delay.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_connective.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_list.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/g_vslider.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/src/x_gui.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/lrshift~/lrshift~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/choice/choice.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/fiddle~/fiddle~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/pique/pique.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/pd~/pdsched.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/pd~/pd~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/bassemu/bassemu~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/stdout/stdout.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/bonk~/bonk~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/riff.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/binaural_processor.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/generic_riff.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/cw_binaural~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/interpolation_candidates.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/raw_wav_hrtfcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/itdcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/logstring.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/delay.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/unprocessed_fixed_size_hrtfcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/ir_key.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/spectral_hrtfcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/flyweight_ir_factory.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/hrtfcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/fft_riff.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/minphase_hrtfcont.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/sigmund~/sigmund~.o ../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/loop~/loop~.o ../../../libs/openFrameworksCompiled/lib/android/x86/libopenFrameworks.a     --sysroot=/home/husk/src/android-ndk-r9b/platforms/android-17/arch-x86/ -nostdlib -L"/home/husk/src/android-ndk-r9b/sources/cxx-stl/gnu-libstdc++/4.8/libs/x86" -shared -Wl,--no-undefined -Wl,--as-needed -Wl,--gc-sections /home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample/bin/libs/libsndfile.a ../../../libs/FreeImage/lib/android/x86/libfreeimage.a ../../../libs/freetype/lib/android/x86/libfreetype.a ../../../libs/tess2/lib/android/x86/libtess2.a  ../../../libs/poco/lib/android/x86/libPocoNetSSL.a ../../../libs/poco/lib/android/x86/libPocoNet.a ../../../libs/poco/lib/android/x86/libPocoCrypto.a ../../../libs/poco/lib/android/x86/libPocoUtil.a ../../../libs/poco/lib/android/x86/libPocoXML.a ../../../libs/poco/lib/android/x86/libPocoFoundation.a ../../../libs/openssl/lib/android/x86/libssl.a ../../../libs/openssl/lib/android/x86/libcrypto.a   -lOpenSLES -lsupc++ -lz -lGLESv1_CM -lGLESv2 -llog -ldl -lm -lc -lgnustl_static -lgcc 
/home/husk/src/android-ndk-r9b/toolchains/x86-4.8/prebuilt/linux-x86/bin/../lib/gcc/i686-linux-android/4.8/../../../../i686-linux-android/bin/ld: error: /home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample/bin/libs/libsndfile.a(sndfile.o): incompatible target
../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/raw_wav_hrtfcont.o:raw_wav_hrtfcont.cpp:function RawWavHrtfCont::set_ir_buffer_from_path(ir_buffer&, std::string): error: undefined reference to 'sf_open'
../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/raw_wav_hrtfcont.o:raw_wav_hrtfcont.cpp:function RawWavHrtfCont::set_ir_buffer_from_path(ir_buffer&, std::string): error: undefined reference to 'sf_read_float'
../../../libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:296: recipe for target 'libs/x86/libOFAndroidApp.so' failed
../../../addons/obj/android/x86/Release/ofxPd/libs/libpd/pure-data/extra/cw_binaural/raw_wav_hrtfcont.o:raw_wav_hrtfcont.cpp:function RawWavHrtfCont::set_ir_buffer_from_path(ir_buffer&, std::string): error: undefined reference to 'sf_close'
collect2: error: ld returned 1 exit status
make[1]: *** [libs/x86/libOFAndroidApp.so] Error 1
make: *** [Release] Error 2
make[1]: Leaving directory '/home/husk/src/of/of_v0.8.3_android_release/examples/android/androidAudioExample'
../../../libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk:126: recipe for target 'Release' failed

**** Build Finished ****

There is one thing I don’t get: why it tries to compile for android/x86 when my arch is arm?
All the Android example compile (and work) this way…so it is aparently right, but still I don’t understand why.

thanks
husk

i haven’t seen that error before, did you compile the liibrary also with the 4.8 toolchain? it’w weird that it won’t work anyway but it’s the only thing that comes to mind

Yes, I used 4.8 toolchain to compile libsndfile.
I will compile it again and see what happen.
Maybe is a linking order iissue: the external needs to link to sndfile.a before other operation occurs.
does make it sense?

husk

yes that’s a common problem with linking, but it doesn’t seem to be the case, that usually happens when you link 2 libraries and one depends on the other but in this case it seems like the dependency is from a source file and the target error is not usually there if it’s just a order problem

Hey Guys any fixes on the incompatible target bug?

Not really, kind of blocked on this project. Taking in consideration using other puredata external, I can’t find any way to make it link correctly.