[pHash-support] Java usage of pHash.java

Evan Klinger eklinger at phash.org
Wed Jan 13 13:21:02 PST 2010


One more quick test case:
remove static from ph_free_datapoint in pHash.h.
Otherwise I will look into it this weekend.

On Wed, Jan 13, 2010 at 12:49 PM, Sebastian Gallese
<sebastiangallese at gmail.com> wrote:
> Evan,
>
> Heh, there is no such thing as "once and for all."  Please do not feel
> obliged to hack away until you have some legitimate free time.
>
> Thank you so much for the help!
>
> -Seb
>
> libtool: link: (cd ".libs" && rm -f "libpHash.so.0" && ln -s
> "libpHash.so.0.0.0" "libpHash.so.0")
> libtool: link: (cd ".libs" && rm -f "libpHash.so" && ln -s
> "libpHash.so.0.0.0" "libpHash.so")
> libtool: link: ar cru .libs/libpHash.a  pHash.o audiophash.o ph_fft.o
> cimgffmpeg.o
> libtool: link: ranlib .libs/libpHash.a
> libtool: link: ( cd ".libs" && rm -f "libpHash.la" && ln -s
> "../libpHash.la" "libpHash.la" )
> make[2]: Leaving directory `/home/kdge/pHash-0.7.2/src'
> Making all in bindings
> make[2]: Entering directory `/home/kdge/pHash-0.7.2/bindings'
> Making all in java
> make[3]: Entering directory `/home/kdge/pHash-0.7.2/bindings/java'
> /bin/bash ../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H
> -I. -I../.. -I../../src  -I/usr/lib/jvm/java-6-sun/include
> -I/usr/local/include -DHAVE_IMAGE_HASH=1 -DHAVE_VIDEO_HASH=1
> -DHAVE_AUDIO_HASH=1 -Dcimg_use_jpeg -Dcimg_use_png  -O2 -ffast-math
> -O3 -MT pHash-jni.lo -MD -MP -MF .deps/pHash-jni.Tpo -c -o
> pHash-jni.lo pHash-jni.cpp
> libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../.. -I../../src
> -I/usr/lib/jvm/java-6-sun/include -I/usr/local/include
> -DHAVE_IMAGE_HASH=1 -DHAVE_VIDEO_HASH=1 -DHAVE_AUDIO_HASH=1
> -Dcimg_use_jpeg -Dcimg_use_png -O2 -ffast-math -O3 -MT pHash-jni.lo
> -MD -MP -MF .deps/pHash-jni.Tpo -c pHash-jni.cpp  -fPIC -DPIC -o
> .libs/pHash-jni.o
> pHash-jni.cpp: In function ‘jboolean
> Java_pHash_00024MVPTree_create(JNIEnv*, _jobject*, _jobjectArray*)’:
> pHash-jni.cpp:155: error: ‘ph_free_datapoint’ was not declared in this scope
> pHash-jni.cpp:174: error: ‘ph_free_datapoint’ was not declared in this scope
> pHash-jni.cpp:204: error: ‘ph_free_datapoint’ was not declared in this scope
> pHash-jni.cpp:220: error: ‘ph_free_datapoint’ was not declared in this scope
> pHash-jni.cpp: In function ‘_jobjectArray*
> Java_pHash_00024MVPTree_query(JNIEnv*, _jobject*, _jobject*, jfloat,
> jint)’:
> pHash-jni.cpp:324: error: ‘ph_free_datapoint’ was not declared in this scope
> pHash-jni.cpp: In function ‘jboolean
> Java_pHash_00024MVPTree_add(JNIEnv*, _jobject*, _jobjectArray*)’:
> pHash-jni.cpp:420: error: ‘ph_free_datapoint’ was not declared in this scope
> make[3]: *** [pHash-jni.lo] Error 1
> make[3]: Leaving directory `/home/kdge/pHash-0.7.2/bindings/java'
> make[2]: *** [all-recursive] Error 1
> make[2]: Leaving directory `/home/kdge/pHash-0.7.2/bindings'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory `/home/kdge/pHash-0.7.2'
> make: *** [all] Error 2
>
> On Wed, Jan 13, 2010 at 3:39 PM, Evan Klinger <eklinger at phash.org> wrote:
>> Looks like there are 2 more that need to be changed that aren't
>> static, ph_compare_images and ph_image_digest. The ones that take a
>> CImg parameter, prepend them with _
>> I think that might solve this once and for all.
>>
>> On Wed, Jan 13, 2010 at 12:24 PM, Sebastian Gallese
>> <sebastiangallese at gmail.com> wrote:
>>> I searched for "static" and placed an underscore in front of each function.
>>>
>>> Looks like overloading is the issue with the error below.  Anything I should do?
>>>
>>> Attached is my pHash.h file.
>>>
>>> In file included from pHash.cpp:25:
>>> pHash.h:263: error: declaration of C function ‘int
>>> ph_image_digest(const char*, double, double, Digest&, int)’ conflicts
>>> with
>>> pHash.h:253: error: previous declaration ‘int ph_image_digest(const
>>> cimg_library::CImg<unsigned char>&, double, double, Digest&, int)’
>>> here
>>> In file included from pHash.cpp:25:
>>> pHash.h:288: error: declaration of C function ‘int
>>> ph_compare_images(const char*, const char*, double&, double, double,
>>> int, double)’ conflicts with
>>> pHash.h:276: error: previous declaration ‘int ph_compare_images(const
>>> cimg_library::CImg<unsigned char>&, const cimg_library::CImg<unsigned
>>> char>&, double&, double, double, int, double)’ here
>>> make[2]: *** [pHash.lo] Error 1
>>> make[2]: Leaving directory `/home/kdge/pHash-0.7.2/src'
>>> make[1]: *** [all-recursive] Error 1
>>> make[1]: Leaving directory `/home/kdge/pHash-0.7.2'
>>> make: *** [all] Error 2
>>>
>>> Thanks,
>>> Seb
>>>
>>>
>>>
>>> On Tue, Jan 12, 2010 at 6:31 PM, Evan Klinger <eklinger at phash.org> wrote:
>>>> Yeah it looks like I didn't rename them all. For the static functions,
>>>> try prepending an _ to the function name to get rid of these errors.
>>>> This weekend I will have more time to resolve all these issues so you
>>>> can move forward rather than debugging.
>>>>
>>>> On Tue, Jan 12, 2010 at 2:10 PM, Sebastian Gallese
>>>> <sebastiangallese at gmail.com> wrote:
>>>>> Evan,
>>>>>
>>>>> Thanks for sending me the updated pHash.h file.  I replaced my old
>>>>> pHash.h file and I got a new error message on building the project:
>>>>>
>>>>> make all-recursive
>>>>> make[1]: Entering directory `/home/kdge/pHash-0.7.2'
>>>>> Making all in src
>>>>> make[2]: Entering directory `/home/kdge/pHash-0.7.2/src'
>>>>> /bin/bash ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I.
>>>>> -I.. -I/usr/lib/jvm/java-6-sun/include -I/usr/local/include
>>>>> -DHAVE_IMAGE_HASH=1 -DHAVE_VIDEO_HASH=1 -DHAVE_AUDIO_HASH=1
>>>>> -Dcimg_use_jpeg -Dcimg_use_png -O2 -ffast-math -O3 -MT pHash.lo -MD
>>>>> -MP -MF .deps/pHash.Tpo -c -o pHash.lo pHash.cpp
>>>>> libtool: compile: g++ -DHAVE_CONFIG_H -I. -I..
>>>>> -I/usr/lib/jvm/java-6-sun/include -I/usr/local/include
>>>>> -DHAVE_IMAGE_HASH=1 -DHAVE_VIDEO_HASH=1 -DHAVE_AUDIO_HASH=1
>>>>> -Dcimg_use_jpeg -Dcimg_use_png -O2 -ffast-math -O3 -MT pHash.lo -MD
>>>>> -MP -MF .deps/pHash.Tpo -c pHash.cpp -fPIC -DPIC -o .libs/pHash.o
>>>>> In file included from pHash.cpp:25:
>>>>> pHash.h:263: error: declaration of C function ‘int
>>>>> ph_image_digest(const char*, double, double, Digest&, int)’ conflicts
>>>>> with
>>>>> pHash.h:253: error: previous declaration ‘int ph_image_digest(const
>>>>> cimg_library::CImg<unsigned char>&, double, double, Digest&, int)’
>>>>> here
>>>>> In file included from pHash.cpp:25:
>>>>> pHash.h:288: error: declaration of C function ‘int
>>>>> ph_compare_images(const char*, const char*, double&, double, double,
>>>>> int, double)’ conflicts with
>>>>> pHash.h:276: error: previous declaration ‘int ph_compare_images(const
>>>>> cimg_library::CImg<unsigned char>&, const cimg_library::CImg<unsigned
>>>>> char>&, double&, double, double, int, double)’ here
>>>>> pHash.h:398: error: declaration of C function ‘MVPRetCode
>>>>> ph_query_mvptree(MVPFile*, DP*, int, float, DP**, int*)’ conflicts
>>>>> with
>>>>> pHash.h:386: error: previous declaration ‘MVPRetCode
>>>>> ph_query_mvptree(MVPFile*, DP*, int, float, DP**, int*, int)’ here
>>>>> pHash.h:417: error: declaration of C function ‘MVPRetCode
>>>>> ph_save_mvptree(MVPFile*, DP**, int)’ conflicts with
>>>>> pHash.h:408: error: previous declaration ‘FileIndex*
>>>>> ph_save_mvptree(MVPFile*, DP**, int, int, int)’ here
>>>>> pHash.h:433: error: declaration of C function ‘int
>>>>> ph_add_mvptree(MVPFile*, DP**, int)’ conflicts with
>>>>> pHash.h:425: error: previous declaration ‘MVPRetCode
>>>>> ph_add_mvptree(MVPFile*, DP*, int)’ here
>>>>> make[2]: *** [pHash.lo] Error 1
>>>>> make[2]: Leaving directory `/home/kdge/pHash-0.7.2/src'
>>>>> make[1]: *** [all-recursive] Error 1
>>>>> make[1]: Leaving directory `/home/kdge/pHash-0.7.2'
>>>>> make: *** [all] Error 2
>>>>>
>>>>> Full output at http://gist.github.com/275677
>>>>>
>>>>> Don't know much about C, but it looks like it might have to do with
>>>>> the "same name but different parameter" methods you mentioned before.
>>>>>
>>>>> Let me know if there is anything else you want me to test out.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Seb
>>>>>
>>>>> On Tue, Jan 12, 2010 at 1:27 PM, Evan Klinger <eklinger at phash.org> wrote:
>>>>>> Sebastian,
>>>>>> I don't think you can put it at the very beginning. It should be after
>>>>>> the #includes. You will also run into another error because some of
>>>>>> the functions have the same name but different parameters, but extern
>>>>>> "C" only expects unique function names. Please try using this header
>>>>>> instead and see if it works. Hang in there - we will get it working
>>>>>> for you.
>>>>>>
>>>>>> Evan
>>>>>>
>>>>>> On Tue, Jan 12, 2010 at 10:20 AM, Sebastian Gallese
>>>>>> <sebastiangallese at gmail.com> wrote:
>>>>>>> Hi Evan,
>>>>>>>
>>>>>>> In pHash-0.7.2/src/pHash.h I added
>>>>>>> extern "C" {
>>>>>>> to the very top of the file and
>>>>>>> }
>>>>>>> to the very bottom of the file.  I got the idea to do that from reading
>>>>>>> http://stackoverflow.com/questions/1041866/extern-c
>>>>>>> and
>>>>>>> http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
>>>>>>>
>>>>>>> I then ran
>>>>>>> sudo CPPFLAGS=-I/usr/lib/jvm/java-6-sun/include ./configure
>>>>>>> --enable-java && sudo make && sudo make install
>>>>>>>
>>>>>>> and I got the output that and uploaded it to http://gist.github.com/275427
>>>>>>>
>>>>>>> It goes haywire around here:
>>>>>>> In file included from /usr/include/c++/4.4/cmath:44,
>>>>>>>                 from /usr/include/CImg.h:75,
>>>>>>>                 from pHash.h:47,
>>>>>>>                 from pHash.cpp:25:
>>>>>>> /usr/include/c++/4.4/bits/cpp_type_traits.h:71: error: template with C linkage
>>>>>>> /usr/include/c++/4.4/bits/cpp_type_traits.h:81: error: template with C linkage
>>>>>>>
>>>>>>> Any thoughts or suggestions would be great!
>>>>>>>
>>>>>>> Thank you,
>>>>>>> Seb
>>>>>>>
>>>>>>> On Mon, Jan 11, 2010 at 2:00 PM, Evan Klinger <eklinger at phash.org> wrote:
>>>>>>>> Sebastian,
>>>>>>>> It looks like the entire API might need to be wrapped in extern "C" to
>>>>>>>> get this to work. To be honest, you're the first that is attempting to
>>>>>>>> use the Java bindings so it's a learning process for both of us. There
>>>>>>>> is an example on how to use the functions in pHash.java in main(). Try
>>>>>>>> adding the extern "C" to all the functions in pHash.h and rebuild and
>>>>>>>> see if that helps. Sorry for the trouble.
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> On Mon, Jan 11, 2010 at 9:30 AM, Sebastian Gallese
>>>>>>>> <sebastiangallese at gmail.com> wrote:
>>>>>>>>> Hi Evan,
>>>>>>>>>
>>>>>>>>> I'm unsure of how I should use pHash with Java.  Do you have some
>>>>>>>>> basic test code or demo code to show me the basic usage?
>>>>>>>>>
>>>>>>>>> For example, right now I'm trying to call on pHash to get a hash from an image.
>>>>>>>>>
>>>>>>>>> I threw the file from pHash-0.7.2/bindings/java/pHash.java into a
>>>>>>>>> package in Eclipse.
>>>>>>>>>
>>>>>>>>> http://github.com/sgallese/sgallese/tree/master/src/pHashTest/
>>>>>>>>>
>>>>>>>>> As you can see from the above code, I have phash.java side by side
>>>>>>>>> with PHashTest.java in a package caled pHashTest
>>>>>>>>>
>>>>>>>>> In PHashTest.java, I just wanted to instantiate pHash, so I have the
>>>>>>>>> following code:
>>>>>>>>>
>>>>>>>>> package pHashTest;
>>>>>>>>>
>>>>>>>>>        public class PHashTest {
>>>>>>>>>            public static void main(String[] args) {
>>>>>>>>>                pHash mypHash = new pHash();
>>>>>>>>>            }
>>>>>>>>>        }
>>>>>>>>>
>>>>>>>>> I kept getting the error "java.lang.UnsatisfiedLinkError: no pHash-jni
>>>>>>>>> in java.library.path" so I searched for pHash-jni on my system and
>>>>>>>>> found these:
>>>>>>>>>
>>>>>>>>> /usr/local/include/pHash-jni.h
>>>>>>>>> /usr/local/lib/libpHash-jni.so
>>>>>>>>> /usr/local/lib/libpHash-jni.so.0
>>>>>>>>> /usr/local/lib/libpHash-jni.so.0.0.0
>>>>>>>>> /usr/local/lib/libpHash-jni.la
>>>>>>>>> /usr/local/lib/libpHash-jni.a
>>>>>>>>>
>>>>>>>>> In Eclipse, I then went to run -> run configurations -> Environment
>>>>>>>>> (tab) and I set LD_LIBRARY_PATH to /usr/local/lib/
>>>>>>>>>
>>>>>>>>> Then I tried to initiate a pHash object again (i.e., pHash mypHash =
>>>>>>>>> new pHash(); ) and I'd get the following error.
>>>>>>>>>
>>>>>>>>> Exception in thread "main" java.lang.UnsatisfiedLinkError:
>>>>>>>>> /usr/local/lib/libpHash-jni.so.0.0.0:
>>>>>>>>> /usr/local/lib/libpHash-jni.so.0.0.0: undefined symbol:
>>>>>>>>> _ZL17ph_free_datapointP12ph_datapoint
>>>>>>>>>        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>>>>>>>>>        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778)
>>>>>>>>>        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
>>>>>>>>>        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
>>>>>>>>>        at java.lang.System.loadLibrary(System.java:1028)
>>>>>>>>>        at pHashTest.pHash.<clinit>(pHash.java:47)
>>>>>>>>>        at pHashTest.PHashTest.main(PHashTest.java:6)
>>>>>>>>>
>>>>>>>>> I figured I'd then try to make an ImageHash object using the code
>>>>>>>>>
>>>>>>>>> ImageHash mypHash = new ImageHash("/home/kdge/Pictures/cc.jpg");
>>>>>>>>>
>>>>>>>>> but ImageHash would not take a string in its constructor.
>>>>>>>>>
>>>>>>>>> Any help is greatly appreciated!
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Seb
>>>>>>>>> _______________________________________________
>>>>>>>>> pHash-support mailing list
>>>>>>>>> pHash-support at lists.phash.org
>>>>>>>>> http://lists.phash.org/listinfo.cgi/phash-support-phash.org
>>>>>>>>>
>>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> pHash-support mailing list
>>>>>>> pHash-support at lists.phash.org
>>>>>>> http://lists.phash.org/listinfo.cgi/phash-support-phash.org
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>



More information about the pHash-support mailing list