PDA

View Full Version : Troubles when compiling pHash



msoftprogramming
June 10th, 2012, 11:40 AM
Hi all,
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-devThen 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

MadCow108
June 10th, 2012, 11:55 AM
libraries need to be behind objects needing them:

$ g++ file.c -lpHash

SevenMachines
June 10th, 2012, 11:57 AM
Most likely you're linking libraries after objects, ie

#g++ -lpHash test.cpp # Wrong!
/tmp/cclknlvN.o: In function `main':
test.cpp:(.text+0x1d): undefined reference to `ph_dct_imagehash'
collect2: ld returned 1 exit status
#g++ test.cpp -lpHash # Right!

For the reason why...
http://www.gentoo.org/proj/en/qa/asneeded.xml
Note, --as-needed is default these days, perhaps a well written explanation should go down as a sticky :)