why plugins in Qt have .dll and .lib files? - qt

Plugins as I know are loaded at run time so they don't need .lib file and a .dll file is adequate to load them at run time. But when you create a plugin in Qt and compile it in, say Windows , you get a .dll file and a .lib file and some other files. The most amazing part of the story is that you don't need to link it to your program if want to use the plugin. So why is it necessary?

It's the standard qmake way of building a shared library, which automatically outputs the import library as well.
Just because it's a plugin and can load it as a plugin, should not mean you can't use it as a library, because a dll is still a library, and plugin-related functions might be useful if exposed through the usual shared library interface.

Related

I cant import a dll into my project references C# .net Project

When I try to import a .dll (cplex1280) into my asp.net project references, I get an error saying Please make sure that the file is accessible, and that it is a valid assembly of COM componet.
The weird thing is that I can build my application even though this dll isn't referenced. For people who are familiar with CPLEX, I successfully included the ILOG.CPLEX.dll and ILOG.Concert.dll
Currently the directory for my project is setup as ProjFolder/Myproj. There is a folder ProjFolder/bin and a folder ProjFolder/myproj/bin where I included the cplex1280.dll file. There is also a copy of the cplex1280.dll in one of my Program Files folder. I tried to add a reference of this dll from each of these locations, but I keep getting the same error. When I looked up this issue, I saw two solutions that people recommended. Here is the post that I used for help.
One solution was trying to use
regsvr32 "foo.dll"
on the file. When I try this, I get an error saying
The module "cplex1280.dll" was loaded but the entry-point DllRegisterServer was not found. make sure that "cplex1280" is a valid DLL or OCX file and then try again.
The other thing I tried using was dll import
[DllImport("cplex1280.dll"]
I was a little confused by the Microsoft documentation. It doesn't specify what folder to put the dll in and usually there is a function definition after the import statement, but my program uses multiple functions from this dll.
If someone could explain this import method in more depth I would appreciate it.
As mentioned in the comments, cplex1280.dll is a Native DLL. It is a shared library for the CPLEX C Callable Library. For your .NET application, you should only add references to ILOG.CPLEX.dll and ILOG.Concert.dll (see the readmeWindows.html file in the directory where you installed CPLEX).
Dropping the CPLEX dll's into your windows/system32 directory is not recommended (see DLL Hell). Instead, when you deploy your application, you either need to make sure that the directory where cplex1280.dll is located is included in the PATH environment variable or that it lives in the same directory as your ASP.NET executables. This gives you more flexibility when you have to support different products that use different versions of CPLEX (or even multiple releases of the same product).

Plugin is not recognized in QML Desktop Appication Deployment

I have wrote a Qt Quick Desktop application in c++ qnd Qt Creator(QML) on Windows7. Now I have to deploy it.
I'm using Qt Quick Desktop Components plugin in my application, I've installed it according to these instructions, and I'm using it with:"import Qt.labs.components", as written there.
I tried adding to the .pro file:
QML_IMPORT_PATH = C:\QtSDK\Desktop\Qt\4.7.4\mingw\imports\Qt\labs\components
but I saw it's working well without it, and I removed it.
I've read a guide how to deploy such an application here, and followed it; I have now a deployment folder, with: the .exe file, the needed dll's, and a folder hierarchy like:Qt/labs/components.
in components I put the styleplugin.dll(for desktop components), and a qmldir file, with the content: plugin styleplugin, excactly like in the doc.
but when I'm runnig my application.exe from the deployment folder in another computer, I'm getting a white, empty window, means: It didn't find the .dll file.
Should you explain me please what's wrong?
I know two reasons, when app can not load plugin dll:
Some of dependecies of the plugin dll are missing or can not be found and that is why it can not be loaded. Qt Creator or Visual Studio environment can be different than the system one. For example, your IDE can modify PATH environment variable. Check plugin's dependencies availability with Microsoft Dependency Walker tool in the same environment where you launch your app.
App can not find plugin in standard directories. To check this you should specify plugin import directory explicitly:
QDeclarativeView *rootView = new QDeclarativeView()
rootView->engine()->addImportPath(QLatin1String("path/to/your/imports"));

Why Qt plugins compiled as .so don't work when deployed in a MacOSX bundle?

I have a CMake project for a Qt based application using plugins.
The standard way to create a plugin is CMake (on all platforms) is with:
ADD_LIBRARY(${PROJECT_NAME} MODULE ...)
This creates a libxxx.so plugin (instead of a libxxx.dylib, if SHARED is used instead of MODULE above).
Now, when running inside an IDE like Xcode or QtCreator, the application works fine, the plugin is loaded and works.
But if I create the .app bundle, the application does not start, saying "libxxx.so is not a valid Qt plugin"! How could be that possible? Maybe some library dependency is not found, but how can i check that? I have used tool -L and I think all the libraries are ok.
You may need a "qt.conf" file in your bundle to tell Qt where the plugins are.
You should read up on CMake's BundleUtilities fixup_bundle function and let it do all that "otool -L" and "install_name_tool" stuff for you.
See this recent related stackoverflow question and answer:
CMake: Copy Frameworks into App Bundle

Compiled distribution of Qt application for windows

I was successfully able to compile and run my Qt application. However, when I move the .exe file outside its original path, I found out that I have to manually copy the Qt DLLs (e.g. mingw10.dll, qtcore4.dll). Is there any dynamic way to link these libraries with my application?
I think you mean you want to "statically" link these libraries with your application.
Basically this means that everything will be rolled inside your exe, and you will have no need of those dlls anymore.
There are advantages to to static linking, but there are also disadvantages as well. You should be absolutely sure that this is what you want to do before you go this way.
Check out this link which explains the difference in depth Dynamic Linking vs Static Linking
As for your specific issue, if you are sure you want to use static linking you will have to change your Qt setup to be built statically. By default the Qt distribution is setup to use dynamic linking. There is a handy guide for that here.
Basically when you setup the build you have to run "configure -static" to change all the project settings to use static linking instead of dynamic linking. And then build Qt over again.
You should also verify your Qt license. If you are using the Qt LGPL license and you want to to link statically you will have to include all your object files (.o and .obj) as Mihai Limbășan wisely explained in his comment. If you have bought and paid for Qt, then you have no problem.
If the DLLs are on the PATH for the application, then they will be found and work. So, you could add where your Qt binaries/dlls are into the %PATH% environment variable. If you're going to create an installer for your application, you'll need to either package these libraries in so they're in the bin directory - or you'll have to expect every user to install and possibly compile Qt themselves (hint: go with the first option. :) )

macdeployqt and third party libraries

I've got an application project that depends on a couple of shared libraries that I have created myself. According to the Qt 4.6 documentation "Deploying an Application on Mac OSX":
Note: If you want a 3rd party library
to be included in your application
bundle, then you must add an excplicit
lib entry for that library to your
application's .pro file. Otherwise,
the macdeployqt tool will not copy the
3rd party .dylib into the bundle.
I have added lib entries to my application's .pro file but the libraries that I have written do not get copied into the bundle when I execute macdeployqt. I have the following in my .pro file:
LIBS += -L../Libraries -lMyLib
Everything builds okay, its just when I try to run from the bundle that I run into problems i.e. "image not found" errors.
Is there a bug in macdeployqt or do I have to something more to my .pro file?
badcat is correct that the Qt 4.6 documentation has a grossly inflated view of what is possible with macdeployqt tool.
In my experience, the only things that are done by macdeployqt are:
Copy the Qt libraries into your app bundle in the foo.app/Contents/Frameworks/ directory
Adjusts the link libraries of one binary, namely foo.app/Contents/MacOS/foo (must have same name as app bundle, even if you mention another binary in Info.plist)
So, for every other binary and library you want to deploy in your app bundle, you must do the following:
Run macdeployqt to enjoy its useful but feebly inadequate benefits
macdeployqt <path_to_your_nascent_app_bundle>/foo.app
Install your extra libraries manually
cp <original_library_path> foo.app/Contents/Frameworks/<lib_name>
Find out what libraries each binary links to.
otool -L <binary_file_name>
Change the internal libary paths in your binaries
install_name_tool -change <original_library_path> #executable_path/../Frameworks/<lib_name> <binary_file_name>
I wrote a perl script that automates these steps for my application, but it's a bit too specific to my particular environment to post here.
You don't need to take care about manual deployment of third-party libraries. I am uploading a patch to Qt that makes it possible to specify additional library search paths, so that the macdeployqt tool finds the third-party dependencies:
https://codereview.qt-project.org/#change,47906
After this one there will be another commit that will add support for third party libraries' deployment.
Did you check the .app bundle to see if the libraries are really not there?
If that's the case, I'd assume there really is a bug in macdeployqt, or it simply can't find the library you are linking. Personally I've never seen macdeployqt actually copy any needed 3rd-party libraries into the bundle.
The interesting part is that macdeployqt never ever works directly with the .pro file. It just does some stuff to the produced application bundle. And after a quick glance into the documentation this Qt 4.7 documentation page obviously proves me right:
Note: If you want a 3rd party library to be included in your application bundle, then you must copy the library into the bundle manually, after the bundle is created.
I'd assume there is a bug in the 4.6 documentation. For me macdeployqt never placed any library files in my bundle (except for the Qt* ones, of course).
I did spend a lot of time with this stuff in my past, and ended up writing a simple little (Python) script that packs everything up into my bundle, changes the library names as needed and puts everything in a .dmg file with automatic naming.
Possibly not what you wanted to hear, but it works. ;)
https://github.com/auriamg/macdylibbundler
dylibbundler is a small command-line programs that aims to make bundling .dylibs as easy as possible. It automatically determines which dylibs are needed by your program, copies these libraries inside the app bundle, and fixes both them and the executable to be ready for distribution... all this with a single command on the teminal! It will also work if your program uses plug-ins that have dependencies too.

Resources