Troubles when compiling phash program

1.6k Views Asked by At

here is some (probably) very simple problem: I'm trying to use the perceptual hashing library pHash with Ubuntu 11.10. I already had ffmpeg installed, by the way this is what I've done:

sudo apt-get install libphash0
sudo apt-get install libphash0-dev

Then tried to compile this program:

#include <iostream>

#include <pHash.h>

using namespace std;

int main()
{
    ulong64 myhash=0;

    ph_dct_imagehash("test.jpg", myhash);
    cout<<myhash<<endl;
}

When compiling, it just prints out:

undefined reference to `ph_dct_imagehash'

Any suggestion? What should I do? Thanks in advance!

Matteo Monti

2

There are 2 best solutions below

1
On

You didn't link to the library. Headers contain definition of library contents. Actual implementation is in library itself. You may link to it either statically or dynamically.

If you're using make, add your library path to makefile and recompile:

LIBS = -L/path/to/your/lib -lyourlib

If library is installed in system, it's probably in one of known paths. (/usr/lib/ or ...). So try adding:

LIBS = -lyourlib

Note: make system interprets -lname as <path>/libname.so. Not always true, but its like almost that.

0
On

You certainly forgot to link the pHash library, so the linker cannot find this function.

Try adding -l pHash to your GCC command line (or update your makefile). If it doesn't work, maybe you'll also need to specify the library path (the location of the *.a file) using -L "/usr/lib/"