[pHash-support] Java usage of pHash.java

Sebastian Gallese sebastiangallese at gmail.com
Tue Jan 12 10:20:03 PST 2010

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

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,

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

More information about the pHash-support mailing list