ndk-r8b cannot link to libjpeg

1,419 views
Skip to first unread message

usual

unread,
Nov 7, 2012, 12:34:48 PM11/7/12
to andro...@googlegroups.com
Hello,

I'm trying to compile a JNI project using libjpeg-turbo.

I successfully build the library thanks to this link
http://stackoverflow.com/questions/12260149/libjpeg-turbo-for-android

But my project can not compile on eclipse:

/home/fabien/android/android-ndk-r8b/ndk-build all
Compile++ thumb : effectsjni <= effectsjni.cpp
In file included from
jni/com_fabien_r_testyourwebcam_opengl2_jni_OpenGL2JniInterface.h:2:0,
from jni/effectsjni.cpp:6:
/home/fabien/android/android-ndk-r8b/platforms/android-14/arch-arm/usr/include/jni.h:592:13:
note: the mangling of 'va_list' has changed in GCC 4.4
Compile++ thumb : effectsjni <= glutil.cpp
Compile++ thumb : effectsjni <= Image.cpp
Prebuilt : libstlport_static.a <=
<NDK>/sources/cxx-stl/stlport/libs/armeabi/
Prebuilt : libjpeg.so <= jni/
SharedLibrary : libeffectsjni.so
./obj/local/armeabi/objs/effectsjni/gltools/Image.o: In function
`Image::savePicture()':
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:291:
undefined reference to `jpeg_std_error(jpeg_error_mgr*)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:292:
undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int,
unsigned int)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:293:
undefined reference to `jpeg_stdio_dest(jpeg_compress_struct*, __sFILE*)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:294:
undefined reference to `jpeg_set_defaults(jpeg_compress_struct*)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:301:
undefined reference to `jpeg_set_quality(jpeg_compress_struct*, int, int)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:302:
undefined reference to `jpeg_start_compress(jpeg_compress_struct*, int)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:310:
undefined reference to `jpeg_write_scanlines(jpeg_compress_struct*,
unsigned char**, unsigned int)'
/home/fabien/workspace/TestYourWebcam/jni/gltools/Image.cpp:313:
undefined reference to `jpeg_finish_compress(jpeg_compress_struct*)'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/libeffectsjni.so] Error 1

**** Build Finished ****

I tried to link the static and the shared library using this Android.mk
file without success:
LOCAL_PATH := $(call my-dir)

# JPEG support
include $(CLEAR_VARS)
LOCAL_MODULE := jpeg
#LOCAL_SRC_FILES := libjpeg.a
LOCAL_SRC_FILES := libjpeg.so
LOCAL_EXPORT_C_INCLUDES :=
/home/fabien/android/android-sdk-linux/sources/external/libjpeg-turbo
#include $(PREBUILT_STATIC_LIBRARY)
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := effectsjni
### Add all source file names to be included in lib separated by a
whitespace
LOCAL_SRC_FILES := effectsjni.cpp gltools/glutil.cpp gltools/Image.cpp
#LOCAL_CFLAGS := -Werror
LOCAL_LDLIBS := -llog -lGLESv2
# Missing includes
LOCAL_C_INCLUDES += /home/fabien/android/spica/sources/glm
# Link to JPEG
#LOCAL_STATIC_LIBRARIES := jpeg
LOCAL_SHARED_LIBRARIES := jpeg
include $(BUILD_SHARED_LIBRARY)

Any hints ?

-
Fabien

olivier...@gmail.com

unread,
Nov 7, 2012, 12:41:38 PM11/7/12
to andro...@googlegroups.com
You probably forgot to include one (or more) .c file while compiling the libjpeg. The linker is not able to find the definition for these function. A quick google on the function name might help you find the missing files.
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>

Onur Cinar

unread,
Nov 7, 2012, 1:23:00 PM11/7/12
to andro...@googlegroups.com
Hi Fabien,

In your Image.cpp, wrap the jpeglib.h include line with extern "C" like this:

extern "C" {
#include <jpeglib.h>
}

Give it a try, and possibly it should work fine now.

If it works, the problem is actually in the jpeglib.h header file:

     30 #ifndef ANDROID
     31 #ifdef __cplusplus
     32 #ifndef DONT_USE_EXTERN_C
     33 extern "C" {
     34 #endif
     35 #endif
     36 #endif

I don't know why they did it this way. When you compile using NDK, this block never gets enabled, so the library won't link properly under C++ code.

Best regards,

-onur

Fabien R

unread,
Nov 8, 2012, 2:53:53 AM11/8/12
to andro...@googlegroups.com
On 07/11/2012 18:41, olivier...@gmail.com wrote:
> You probably forgot to include one (or more) .c file while compiling the libjpeg. The linker is not able to find the definition for these function. A quick google on the function name might help you find the missing files.
>
I found the missing functions witn "nm".
-
Fabien

usual

unread,
Nov 8, 2012, 9:01:26 AM11/8/12
to andro...@googlegroups.com
On 07/11/2012 19:23, Onur Cinar wrote:
> Hi Fabien,
>
> In your Image.cpp, wrap the jpeglib.h include line with extern "C"
> like this:
>
> *extern "C" {
> *
> #include <jpeglib.h>
> *}
> *
>
Thanks Onur,
I forgot that this statement was required to include C headers.
-
Fabien

Onur Cinar

unread,
Nov 8, 2012, 10:13:32 AM11/8/12
to andro...@googlegroups.com
Hi Fabien,

I'm glad that it worked.   Yes, it is required to instruct the compiler about the linkage style.  Normally it should be done in the jpeglib.h header file so that you don't have to remember it each time, but looks like for some reason they disabled it for Android by assuming that Android is C only.

Best regards,

-onur

Marcus Moran

unread,
Nov 7, 2012, 8:45:15 PM11/7/12
to andro...@googlegroups.com
You may want to take a look of the linaro project. http://www.linaro.org/linux-on-arm/meet-the-team/tom-gall/
Tom can probably give you valuable help.
 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/fkK1I9CVkIcJ.

David Turner

unread,
Nov 12, 2012, 8:30:13 AM11/12/12
to andro...@googlegroups.com
On Thu, Nov 8, 2012 at 4:13 PM, Onur Cinar <onur....@gmail.com> wrote:
Hi Fabien,

I'm glad that it worked.   Yes, it is required to instruct the compiler about the linkage style.  Normally it should be done in the jpeglib.h header file so that you don't have to remember it each time, but looks like for some reason they disabled it for Android by assuming that Android is C only.

FWIW, there is nothing specific to Android here. The original libjpeg headers are simply not compatible with C++ inclusion, so they need to be guarded explicitely with an extern "C" {} block in any C++ source code that includes them.
 
Best regards,

-onur


On Thursday, November 8, 2012 6:01:55 AM UTC-8, Fabien R wrote:
On 07/11/2012 19:23, Onur Cinar wrote:
> Hi Fabien,
>
> In your Image.cpp, wrap the jpeglib.h include line with extern "C"
> like this:
>
> *extern "C" {
> *
> #include <jpeglib.h>
> *}
> *
>
Thanks Onur,
I forgot that this statement was required to include C headers.
-
Fabien

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/mrBwCRo9LIoJ.
Reply all
Reply to author
Forward
0 new messages