QMYSQL driver not loaded, tried all hints - c++

iam writing an C++ application with QT 5.3 using QT-Creator as IDE on mac os 10.8.
The problem appears when iam trying to load the QMYSQL plugin with
db = QSqlDatabase::addDatabase("QMYSQL");
it results in
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
so I tried
loader.setFileName("/Users/kilian/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib");
qDebug() << loader.load();
qDebug() << loader.errorString();
to get a better output
"Die Bibliothek /Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib kann nicht geladen werden:
(dlopen(/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib, 5):
Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib
Reason: image not found)"
So I tried otool
otool -L build-$appname-Desktop-Debug/$appname.app/Contents/MacOS/$appname
build-$appname-Desktop-Debug/$appname.app/Contents/MacOS/$appname:
/usr/local/mysql/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/Users/foob/Qt/5.3/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.3.0, current version 5.3.0)
/Users/foob/Qt/5.3/clang_64/lib/QtSql.framework/Versions/5/QtSql (compatibility version 5.3.0, current version 5.3.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
As information, I built the QMYSQL Plugin by myself with
$cd Qt/5.3/Src/qtbase/src/plugins/sqldrivers/mysql/
$qmake "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/mysql/lib -lmysqlclient_r" mysql.pro
$ make
make -f Makefile.Release all
make[1]: Nothing to be done for `all'.
make -f Makefile.Debug all
make[1]: Nothing to be done for `all'.
$ make install
make -f Makefile.Release install
cp -f "../../../../plugins/sqldrivers/libqsqlmysql.dylib" "/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql.dylib"
cp -f /Users/foob/Qt/5.3/Src/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /Users/foob/Qt/5.3/clang_64/lib/cmake/Qt5Sql/
make -f Makefile.Debug install
cp -f "../../../../plugins/sqldrivers/libqsqlmysql_debug.dylib" "/Users/foob/Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib"
cp -f /Users/foob/Qt/5.3/Src/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /Users/foob/Qt/5.3/clang_64/lib/cmake/Qt5Sql/
Everythink seems fine, i set earlier DYLD_LIBRARY_PATH in /etc/profile
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH
results in
/usr/local/mysql/lib:
The folder /usr/local/mysql/lib :
$ls -lisa /usr/local/mysql/lib/
total 556840
2147230 0 drwxr-xr-x 12 root wheel 408 21 Jun 00:01 .
2147093 0 drwxr-xr-x 17 root wheel 578 21 Jun 00:01 ..
2147231 8384 -rwxr-xr-x 1 root wheel 4289380 6 Mai 13:18 libmysqlclient.18.dylib
2147232 20744 -rw-r--r-- 1 root wheel 10620040 6 Mai 13:18 libmysqlclient.a
2147233 8 lrwxr-xr-x 1 root wheel 23 21 Jun 00:01 libmysqlclient.dylib -> libmysqlclient.18.dylib
2147234 8 lrwxr-xr-x 1 root wheel 23 21 Jun 00:01 libmysqlclient_r.18.dylib -> libmysqlclient.18.dylib
2147235 8 lrwxr-xr-x 1 root wheel 16 21 Jun 00:01 libmysqlclient_r.a -> libmysqlclient.a
2147236 8 lrwxr-xr-x 1 root wheel 20 21 Jun 00:01 libmysqlclient_r.dylib -> libmysqlclient.dylib
2147237 261360 -rw-r--r-- 1 root wheel 133814816 6 Mai 13:08 libmysqld-debug.a
2147239 266288 -rw-r--r-- 1 root wheel 136335512 6 Mai 13:18 libmysqld.a
2147240 32 -rw-r--r-- 1 root wheel 14544 6 Mai 13:18 libmysqlservices.a
2147241 0 drwxr-xr-x 17 root wheel 578 6 Mai 13:21 plugin
The related parts of the .pro file iam using
macx: {
INCLUDEPATH += /usr/local/mysql/include \
/Users/foob/Qt/5.3/clang_64/include
}
macx: {
LIBS += -L/usr/local/mysql/lib -lmysqld -lmysqlclient -v
}
Does anyone have an hint what iam doing wrong?
P.S. I changed User & App name for privacy.

Fixed the issue, wasn't aware its possible to use otool and install_name_tool for dylibs too.
Simply did it with
install_name_tool -change libqsqlmysql_debug.dylib /Users/foob/Qt/5.3/Src/qtbase/plugins/sqldrivers/libqsqlmysql_debug.dylib Qt/5.3/clang_64/plugins/sqldrivers/libqsqlmysql_debug.dylib
Now it works. Does anyone knows why the libs aren't found in the first place? I checked the Makefile produced by qmake and it seems fine. Strange Mac ...

Related

Using Freetype library with CMake [duplicate]

I'm new to cmake, and I'm only using it to install opencv on my ubuntu linux.
Here's the command I ran: cmake -DCMAKE_BUILD_TYPE=Release DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source
Then it returns the error:
FATAL: In-source builds are not allowed. You should create separate directory for build files.
My current directory, ~/OCV/build/opencv, does contain the CMakefiles.txt file, so that's not the problem. I tried to change the directory in my command, but they all raise the same error. I saw the other answers on this issue, so I erased CMakeFiles directory and CMakeCache.txt file every time before I ran the command, but none of them worked.
Thanks.
It wants you to create a separate build directory (anywhere), and run cmake there. For example:
mkdir my_build_dir
cd my_build_dir
rm ../CMakeCache.txt
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source
Note the .. in this example telling cmake where to look for the source.
In case you didn't remove CMakeCache.txt before building again, it will still show this error.
So, please remember to delete CMakeCache.txt first before running cmake.
After you have success downloaded and unzipped OpenCV sources from sources you need create simple command-file install.sh. For example, your working dir will be /home/user/myopencv
So /home/user/myopencv/install.sh will be contain next code:
#!/bin/bash
rm CMakeCache.txt
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local
make
make install
make clean
Next
chmod 777 install.sh
./install.sh
And after the all you will get those executable files:
root#cartman:/usr/local/bin# ls -las | grep opencv
32 -rwxr-xr-x 1 root root 29888 апр 20 18:10 opencv_annotation
244 -rwxr-xr-x 1 root root 247608 апр 20 18:10 opencv_createsamples
244 -rwxr-xr-x 1 root root 247504 апр 20 18:10 opencv_haartraining
20 -rwxr-xr-x 1 root root 18600 апр 20 18:10 opencv_performance
288 -rwxr-xr-x 1 root root 294592 апр 20 18:10 opencv_traincascade
16 -rwxr-xr-x 1 root root 14288 апр 20 18:10 opencv_version
60 -rwxr-xr-x 1 root root 61040 апр 20 18:10 opencv_visualisation
Enjoy!

"string.h" not found message in building qt app for iOS

I've recently updated Xcode to version 10.0 and after that when I try to build version for iOS I've the following problem.
1:04:17: Running steps for project Diasteca...
11:04:17: Starting: "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" /Users/belladellifabio/Desktop/QtProjects/Diasteca/mqtt_test/mqtt_test.pro -spec macx-ios-clang CONFIG+=iphoneos CONFIG+=device CONFIG+=qml_debug
Project MESSAGE: This project is using private headers and will therefore be tied to this specific Qt module build version.
Project MESSAGE: Running this project against other versions of the Qt modules may crash at any arbitrary point.
Project MESSAGE: This is not a bug, but a result of using Qt internals. You have been warned!
11:04:18: The process "/Users/belladellifabio/Qt/5.11.1/ios/bin/qmake" exited normally.
11:04:18: Starting: "/usr/bin/make" qmake_all
make: Nothing to be done for `qmake_all'.
11:04:18: The process "/usr/bin/make" exited normally.
11:04:18: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -fPIC -std=gnu++11 -arch arm64 -arch x86_64 -Xarch_arm64 -miphoneos-version-min=12.0 -Xarch_arm64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -Xarch_x86_64 -mios-simulator-version-min=12.0 -Xarch_x86_64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk -fobjc-nonfragile-abi -fobjc-legacy-dispatch -fembed-bitcode-marker -Wall -W -DQT_COMPILER_SUPPORTS_SSE2 -DMQTT_TEST_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I../../Diasteca/mqtt_test -I. -I../../../../Qt/5.11.1/ios/mkspecs/common/uikit -I../../../../Qt/5.11.1/ios/include -I../../../../Qt/5.11.1/ios/include/QtNetwork -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1 -I../../../../Qt/5.11.1/ios/include/QtCore/5.11.1/QtCore -I../../../../Qt/5.11.1/ios/include/QtCore -I. -I../../../../Qt/5.11.1/ios/mkspecs/macx-ios-clang -o qmqttclient.o ../../Diasteca/mqtt_test/qmqttclient.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.3.sdk' [-Wmissing-sysroot]
In file included from ../../Diasteca/mqtt_test/qmqttclient.cpp:30:
In file included from ../../Diasteca/mqtt_test/qmqttclient.h:33:
In file included from ../../Diasteca/mqtt_test/qmqttglobal.h:33:
In file included from ../../../../Qt/5.11.1/ios/include/QtCore/qglobal.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:202:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
Probably the real problem is not the file not found error, but is connected to the fact that qty tries to build the app using an SDK that is no more installed on the system. Is this a qt problem? How could I specify the version of iOS SDK to use to build the app? Is it possible?
Finally, I've found and delete .qmake.cache and .qmake.stash files. I've restart QtCreator and now it seems to work.
Qt stores SDK information somewhere deep in the build output and the .pro.user file.
Remove the user file (you might want to backup your user file in case you have custom build steps), the complete (shadow) build tree and modify your .pro file so that there is no such line as QMAKE_MAC_SDK = macosx10.13.
Then call qmake and build your project again, the inconsistency should be gone.
This occurs when the iOS SDK that Qt is expecting is different than the iOS SDK that you have installed. For instance Qt 5.13.1 expects iPhoneOS13.1.sdk but my Xcode currently has iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
To remedy this, we can get Qt to use the iPhoneOS13.2.sdk:
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 7 root wheel 224 Nov 5 2019 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ sudo ln -s iPhoneOS.sdk iPhoneOS13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:20 iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jul 22 14:20 iPhoneOS13.1.sdk -> iPhoneOS.sdk
lrwxr-xr-x 1 root wheel 12 Jan 15 2020 iPhoneOS13.2.sdk -> iPhoneOS.sdk
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
$ sudo ln -s iPhoneSimulator.sdk iPhoneSimulator13.1.sdk
$ ls -l
total 0
drwxrwxr-x 8 root wheel 256 Jul 22 14:14 iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jul 22 14:39 iPhoneSimulator13.1.sdk -> iPhoneSimulator.sdk
lrwxr-xr-x 1 root wheel 19 Jan 15 2020 iPhoneSimulator13.2.sdk -> iPhoneSimulator.sdk
I met a similar problem, because my xcode project was created by different XCode SDK, and it's generated by CMake, so I deleted the cache and solved the problem.

Cross-compile for ARM: undefined reference to '__fdelt_chk#GLIBC_2.15'

Following this howto I'm cross-compiling a bluetooth application for Raspberry Pi (ARM). When I try to link with libbluetooth I get the error below. Even the simplest helloworld application (without bluetooth code) won't link.
arm-linux-gnueabihf-g++ -c hello.cpp -o hello.o
arm-linux-gnueabihf-g++ hello.o -o hello -lbluetooth -L/home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf
/home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth.so: undefined reference to `__fdelt_chk#GLIBC_2.15'
sbf#sbf-VirtualBox ~/raspberrypi/projects/test $ ls -al /home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth*
-rw-r--r-- 1 sbf sbf 132886 May 27 2016 /home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth.a
lrwxrwxrwx 1 sbf sbf 23 Nov 24 21:20 /home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth.so -> libbluetooth.so.3.17.11
lrwxrwxrwx 1 sbf sbf 23 Nov 24 21:20 /home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth.so.3 -> libbluetooth.so.3.17.11
-rw-r--r-- 1 sbf sbf 103376 May 27 2016 /home/sbf/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libbluetooth.so.3.17.11
Edit (added):
GLIBC Version 2.19
pi#raspberrypi:~ $ ldd --version
ldd (Debian GLIBC 2.19-18+deb8u6) 2.19
What's going wrong?
I was experiencing the same issue yesterday trying to link libbluetooth using raspberry pi tools.
To solve this I downloaded a newer version of Linaro dev tools (6.1.1) than what is supplied by the raspberry pi tools repository.
Here is the link to the latest linaro toolchain release
Download "gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabihf.tar.xz" and put that folder in your raspberrypi/tools/arm-bcm2708/ directory along with the other toolchains.
Then set compiler/linker paths to point to the new directory.
(I am using cmake)
SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++)
(edit) I had trouble running my executable with this version of the toolchain compiled since jessie doesn't support gcc versions 5 or 6. Instead try using this release https://releases.linaro.org/components/toolchain/binaries/4.9-2016.02/arm-linux-gnueabihf/

QSqlDatabase: QMYSQL driver not loaded on Xubuntu 16.04 64bits

I'm trying to follow the answer given in QSqlDatabase: QMYSQL driver not loaded on Ubuntu 15.04 64bits
on Xubuntu 16.04, where:
# ls /usr/lib/x86_64-linux-gnu/libmysql* -ls
5624 -rw-r--r-- 1 root root 5757198 Abr 21 10:30 /usr/lib/x86_64-linux-gnu/libmysqlclient.a
0 lrwxrwxrwx 1 root root 20 Abr 21 10:29 /usr/lib/x86_64-linux-gnu/libmysqlclient.so -> libmysqlclient.so.20
0 lrwxrwxrwx 1 root root 24 Abr 21 10:29 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 -> libmysqlclient.so.20.2.1
4140 -rw-r--r-- 1 root root 4237408 Abr 21 10:30 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.2.1
Here there are no *_r terminated files.
However, make seems to search for *_r terminated files:
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: error: ld returned 1 exit status
Makefile:111: recipe for target '../../../../plugins/sqldrivers/libqsqlmysql.so' failed
make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1
From What is difference between libmysqlclient.a and libmysqlclient_r.a? it seems just a link must be made between the two. Is this the correct approach? Should I do it manually like:
cd /usr/lib/x86_64-linux-gnu/
ln -s libmysqlclient.so.20.2.1 libmysqlclient_r.so.20.2.1
ln -s libmysqlclient.so.20 libmysqlclient_r.so.20
ln -s libmysqlclient.so libmysqlclient_r.so
ln -s libmysqlclient.a libmysqlclient_r.a
Or I'm missing some thing?

How to build pHash on MacOSX Lion (using latest ffmpeg-devel)

Building pHash 0.9.4 on OSX can turn out to be tricky.
For those of you who've run into issues, my somewhat lengthy answer below might help.
Make sure you've got macports fully updated and working. This means a recent Xcode, and inside Xcode preferences->downloads->components install Command-Line Tools !
$ sudo port selfupdate
# if you've had previous build issues:
$ sudo port clean --all
# get pHash
wget http://www.phash.org/releases/pHash-0.9.4.tar.gz
tar zxvf pHash-0.9.4.tar.gz
cd pHash-0.9.4
# remove old versions of ffmpeg, e.g.
$ sudo port installed ffmpeg
$ sudo port uninstall --follow-dependents ffmpeg #0.7.11_1+mmx
$ sudo port uninstall --follow-dependents ffmpeg #0.7.8_0
# install latest ffmpeg-devel version (#20120329 for me) - enable the non-free stuff as well
$ sudo port install ffmpeg-devel +nonfree
# double check that you have some new header files
$ ll -tr /opt/local/include/
total 8816
-rw-r--r-- 1 root admin 191 Dec 23 2004 lua.hpp
-rw-r--r-- 1 root admin 1026 Dec 27 2007 lualib.h
-rw-r--r-- 1 root admin 5777 Dec 27 2007 lauxlib.h
...
drwxr-xr-x 6 root admin 204 Jul 12 17:27 libmodplug
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libswscale
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libswresample
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libpostproc
drwxr-xr-x 41 root admin 1394 Jul 12 17:32 libavutil
drwxr-xr-x 5 root admin 170 Jul 12 17:32 libavformat
drwxr-xr-x 8 root admin 272 Jul 12 17:32 libavfilter
drwxr-xr-x 3 root admin 102 Jul 12 17:32 libavdevice
drwxr-xr-x 10 root admin 340 Jul 12 17:32 libavcodec
# get CImg and copy CImg.h into your pHash dir
$ cd ..
$ wget http://downloads.sourceforge.net/project/cimg/CImg-1.5.0.zip
$ unzip CImg-1.5.0.zip
$ cp CImg-1.5.0/CImg.h pHash-0.9.4/
$ cd pHash-0.9.4
# copy the JNI headers from your Java SDK into your pHash dir - for 1.7.0 they're here:
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/jni.h ./
$ cp /Library/Java//JavaVirtualMachines/1.7.0.jdk/Contents/Home/include/darwin/jni_md.h ./
# install libsndfile, libsamplerate and mpg123 if not installed already
$ sudo port install libsndfile
$ sudo port install libsamplerate
$ sudo port install mpg123
# now run configure, with Java enabled as you likely want those cool bindings, and expect the missing libavcodec error:
$ ./configure --enable-java
OR this which would make more sense:
$ ./configure --enable-java CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"
but configure completely ignores the new include/lib paths stated :( Seemingly as they're hardcoded inside configure.
...
checking CImg.h usability... no
checking CImg.h presence... no
checking for CImg.h... no
checking whether CImg.h is in the current or src directory.... yes
*** Configuring video Hash ***
checking whether FFmpeg is present... checking for avcodec_alloc_frame in -lavcodec... no
configure: error:
*** libavcodec not found.
So then since configure expects all the libs and includes to be in /usr/local/ (not /opt/local) and I cant't get it to look elsewhere, the only thing left to do is brute-force it ! :D
# edit ./configure as follows
$ nano configure
CTRL-W -> search for ' -L/' (note the space)
# edit the lines as follows
LDFLAGS="$LDFLAGS -L/usr/local/lib -L/opt/local/lib"
CPPFLAGS="$CPPFLAGS -I/usr/local/include -I/opt/local/include"
# Or do the newbie version (I actually did this the first time!)
$ sudo mv /usr/local/lib /usr/local/lib-foo
$ sudo mv /usr/local/include/ /usr/local/include-foo
$ sudo ln -s /opt/local/lib /usr/local/lib
$ sudo ln -s /opt/local/include /usr/local/include
$ ll /usr/local/
total 16
drwxr-xr-x 32 root wheel 1088 Jun 29 18:04 bin
drwxr-xr-x 3 root wheel 102 Mar 6 14:40 etc
lrwxr-xr-x 1 root wheel 18 Jul 12 19:27 include -> /opt/local/include
drwxr-xr-x 11 root wheel 374 Jul 12 19:22 include-foo
lrwxr-xr-x 1 root wheel 14 Jul 12 19:27 lib -> /opt/local/lib
drwxr-xr-x 25 root wheel 850 Jul 12 19:23 lib-foo
drwxr-xr-x 8 root wheel 272 Oct 11 2010 sbin
drwxr-xr-x 4 root wheel 136 Jun 12 11:52 share
# at this point ./configure should work ok
Time to run make - you'll get a bunch of errors:
$ make
# on to the code bits:
# we need to adjust src/cimgffmpeg.cpp to support the latest version of ffmpeg
# a few things have moved from being deprecated to having been completely changed:
$ make 2>&1 | grep error
cimgffmpeg.cpp:57: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:70: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:134: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:202: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:216: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:283: error: 'avcodec_decode_video' was not declared in this scope
cimgffmpeg.cpp:339: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:357: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:368: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
cimgffmpeg.cpp:399: error: 'av_open_input_file' was not declared in this scope
cimgffmpeg.cpp:410: error: 'CODEC_TYPE_VIDEO' was not declared in this scope
# change as follows; left: original downloaded source, right: modified source
$ diff ~/Downloads/pHash-0.9.4-fresh/src/cimgffmpeg.cpp ~/dev/pHash-0.9.4/src/cimgffmpeg.cpp
57c57
< if(av_open_input_file(&st_info->pFormatCtx, st_info->filename, NULL, 0, NULL)!=0)
---
> if(avformat_open_input(&st_info->pFormatCtx, st_info->filename, NULL, NULL)!=0)
70c70
< if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
134c134
< avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
---
> avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);
202c202
< if(av_open_input_file(&(st_info->pFormatCtx),st_info->filename,NULL,0,NULL)!=0){
---
> if(avformat_open_input(&(st_info->pFormatCtx),st_info->filename,NULL,NULL)!=0){
216c216
< if(st_info->pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(st_info->pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
282,283c282
< avcodec_decode_video(st_info->pCodecCtx, pFrame, &frameFinished,
< packet.data,packet.size);
---
> avcodec_decode_video2(st_info->pCodecCtx, pFrame, &frameFinished, &packet);
339c338
< if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, file, NULL, NULL))
357c356
< if (av_open_input_file(&pFormatCtx, file, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, file, NULL, NULL))
368c367
< if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
399c398
< if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL))
---
> if (avformat_open_input(&pFormatCtx, filename, NULL, NULL))
410c409
< if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
---
> if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
That was tons of fun I'm sure, no worries we're almost there.
# make should now complete with only useless warnings
$ make
$ sudo make -n install
# if all went well you've not got pHash with Java bindings
# let's build the Java files and test it
$ cd ll bindings/java/org/phash/
$ javac *.java
# go back to the Java bindins root and run
$ cd ../..
# oh yeah.. if you actually DID rename the include/lib dirs previously then:
$ sudo rm /usr/local/lib
$ sudo rm /usr/local/include
$ sudo mv /usr/local/include-foo/ /usr/local/include
$ sudo mv /usr/local/lib-foo/ /usr/local/lib
# drum roll..
$ java -Djava.library.path=/usr/local/lib org/phash/pHash -mh ~/Downloads/s01.jpg ~/Downloads/s02.jpg
File 1: /Users/xxx/Downloads/s01.jpg
File 2: /Users/xxx/Downloads/s02.jpg
0.3159722222222222
# now go try out your image recognition app ideas ;)