Visual Studio Qt tools, making dll
-
Hello everyone,
I am using VS 2019 and want to use Qt Classes, such as QFile, QDir and some other for my solution, to do that I have installed VS Qt Tools. The solution I am creating is dynamic library (.dll). Everything is compiling but when I try to launch the application that uses this dll, i get an error: "Unable to find an entry point named 'isEmpty@Dir...' in DLL".
To create this dll I have created empty qt project and changed Configuration Type to Dynamic lybrary (.dll) in Projects Properties->Configuration properties->General.
As I can understand from error output the problem is that on runtime the application can't find function isEmpty() from QDir class. Could this happen because by default qt applications link dynamicly with all its dependenies, so when I compile my dll, qt funtions are not present there, and Visual Studio expects this funtion to be dynamicly linked.
So what solution to this problem do you suggest? Do I need to build qt by myself using "configure -static", and then in VS Qt Tools use newly compiled Qt version with static linking, or there is another solution?
Some additional information: I am using Qt 5.9.9 installed by qt_online_installer (opensource edition). Application that uses my dll is third-party app. It has some API requirments to my dll and uses dll's functions inside (don't think it is too important, but want to explain as much as possible, maybe this helps). -
@Beatler said in Visual Studio Qt tools, making dll:
i get an error: "Unable to find an entry point named 'isEmpty@Dir...' in DLL".
How did you deploy your DLL and its dependencies? Did you use
windeployqt
? (see https://doc.qt.io/qt-5/windows-deployment.html ) -
If you want to have a single dll file then everything your app uses must be inside it, including Qt's code, so yeah, you need to build Qt statically and link to it and all of its dependencies (e.g. your toolchain's runtime libraries).
Since you're using the open source Qt version take notice of the license. Open source license requires users to be able to re-link your app with their version of Qt, so If you're gonna link statically this pretty much means you have to open source your dll's code too (or go with commercial license).
-
@Chris-Kawa thank you for your reply, I will try static linking and will open my dll's code.
-
@Beatler said in Visual Studio Qt tools, making dll:
I didn't used windeployqt, because I want to create single Dll file.
You got the error, "Unable to find an entry point named 'isEmpty@Dir...' in DLL", because your software needs to load
Qt5Core.dll
. This is how it works without static linking.@Chris-Kawa thank you for your reply, I will try static linking and will open my dll's code.
As @Chris-Kawa said, be sure to consider the licensing requirements for static linking.
-
For those who might be interested. My main mistake was the following: I have installed qt with qt installer. By default it installs dynamic version of Qt. So it needs Qt dll's on runtime to operate. To avoid that need in Qt dll's I had to firstly configure Qt to create static libraries instead of dynamic ones (by setteng -static option for configure.exe) and then compile Qt from source by myself. After that I have added this newly compiled version to my VS and used it to build my solution and now everything works.
After all I can't use this solution :-) Cause I can't make my code opensource. I will rewrite it with STL)) But this is cool experience, cause I learned something today) -
@Beatler said in Visual Studio Qt tools, making dll:
After all I can't use this solution :-) Cause I can't make my code opensource. I will rewrite it with STL
That's a shame. All the best with your project!
-
Hi,
@Beatler said in Visual Studio Qt tools, making dll:After all I can't use this solution :-) Cause I can't make my code opensource. I will rewrite it with STL)) But this is cool experience, cause I learned something today)
That might not be necessary but you'll have some work to do. The LGPL state that your application users shall be able to switch these libraries if they want to. In the case of a static build, it means that you must provide them with the build artifacts of your application so they can link their versions of the libraries. So the simple way is to use dynamic builds because they can just change the library files. Note that these artifacts must match the released version they are using.