How can I create a cross-platform Qt app which uses OpenCV?
-
I have compiled the OpenCV library & places the dylibs into a folder and included the dylibs by writing
LIBS += /myproject/...executablepath/opencv_lib/*.dylib in my project's .pro fileThe above works if I have files in /usr/local/lib, however it does NOT work when these dylibs are not there in /usr/local/lib.
I want to create a Qt app which "bundles" OpenCV with it, such that the user does NOT need to install OpenCV himself before running the app. Now that I have already included the dylibs in my project, why should the libraries need to be there in /usr/local/lib also?
Please help!
-
Two things you should know:
-
Your shared library should be found by linker at the build time. You have done this by passing it to the linker.
-
You shared library should be found by your application at the run time. Seems you have forget this.
You can use environment variable such as %PATH% under windows, $LD_LIBRARY_PATH under linux, and $DYLD_LIBRARY_PATH under macos.
or you can use rpath or loader_path for *nix system.
-
-
To add to what 1+1=2 said, you can also compile OpenCV statically and link to these libraries so there would be no need to install them
-
What doesn't work ?
-
Indeed that's strange, you should go to the OpenCV forum to get help for building it statically.
In between, if you want to use the dynamic version, use 1+1=2's advice. The technique is explained there
[quote author="1+1=2" date="1378187807"]
You can use environment variable such as %PATH% under windows, $LD_LIBRARY_PATH under linux, and $DYLD_LIBRARY_PATH under macos.
[/quote] -
Hi, this is not a Qt problem, this is a common system concept and it is valid for C/C++/fortran/...
When shared library used, you must tell your application where the library can be found if it's not located in system default path.
There are two ways to do so.
- The first one is make use of system variable
- Another one is embedded the library path, which is the installed path of your library when your deploy your application, to you application when you build your application.
[quote author="prerna" date="1378220070"]1+1=2 can you please be more specific about how to the #2 in Qt? I am still very new to Qt.[/quote]
-
Hey! Well, it worked now! I understand that this is not a Qt problem. I have faced this before as well and gotten it to work. Problem was that I had tried setting DYLD_LIBRARY_PATH to /Users/..../project/deploy/lib i.e. an absolute path and it did not work!
My working directory and DESTDIR is /Users/..../project/deploy. So, I tried setting DYLD_LIBRARY_PATH to ./lib and it worked perfectly![quote author="1+1=2" date="1378257473"]Hi, this is not a Qt problem, this is a common system concept and it is valid for C/C++/fortran/...
When shared library used, you must tell your application where the library can be found if it's not located in system default path.
There are two ways to do so.
- The first one is make use of system variable
- Another one is embedded the library path, which is the installed path of your library when your deploy your application, to you application when you build your application.
[quote author="prerna" date="1378220070"]1+1=2 can you please be more specific about how to the #2 in Qt? I am still very new to Qt.[/quote]
[/quote]