Libxl + windows + QT - c++

I installed libxl package file from offcial website. It contains header files in include_cpp folder and libxl.lib in libs folder. I am using QT(cpp) to run my project. I was able to link libxl package to QT in linux (by editing its .pro file by right clicking and adding lib path and include path.). The same in windows is not working. Sometimes it runs the console empty and later on executing again throws an error that .dll files are missing( even when I have added
CONFIG += static
in .pro file.)
I even tried downloading static linking package of libxl and adding the .lib files to QT but still had no good luck.

add this to the INCLUDEPATH: being careful to replace with the correct location of the library
-isystem "C:\path\to\libxl\"
and report back if that helps. this may be considered a hack but it worked for me a few times when problems arose linking boost libraries in windows

You should be fine by adding
win32:LIBS += -LD:/PATH/TO/LIB -lxl
win32:INCLUDEPATH += D:/PATH/TO/LIBHEADERS/
to your .pro file.

Sometimes it runs the console empty and later on executing again throws an error that .dll files are missing
If application compiles cleanly without linking errors yet throwing missing dll errors on start then application can't locate dll files. Dlls should be in the same dir as app is or in dirs in your PATH environment variable. There's also "manifests" thing on windows that can prevent app from loading dll when conditions mentioned above are met.
There's depends.exe tool to inspect dlls app depends on.
even when I have added CONFIG += static in .pro file.
I think setting static in your project file CONFIG var don't change anything. To get static build you must compile qt with static option.

Related

Qt Release DLL Error

I have a project in Qt Creator and am trying to compile a static release. To do so, I have added "static" to my "CONFIG" option in my .pro file.
After rebuilding all the files, I get a folder named "release" with an executable and a few other files inside of it. When trying to execute the generated file, I get an error that reads as such:
"The procedure entry point __cxa_throw_bad_array_new_length could not be located in the dynamic link library C:\Qt\5.5\mingw492_32\bin\QtCore.dll"
This error message remains whether I use mingw 5.5.0 or 5.4.2 to compile the files.
Using dependency walker and coping the "correct" QT dll files also does not resolve the problem.
What I know already: This error happens to people who copy the wrong QTCore.dll to their project folder. However, since I am not copying any .dll files, I don't know how to use this information to my advantage.
In conclusion, my question is: How do I stop this error from occurring? Moreover, is there a better way to statically compile a qt application?
To build static release of your application you basically need two things:
1) add
CONFIG += static
in your .pro file (you did it) and don't copy any Qt dlls.
2) you need to build static Qt
https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
By default Qt is installed prepared for dynamic linking, this is why you need to build static Qt on your own.
You may want to look also at this great Q&A:
Qt static linking and deployment
but it deals mainly with Qt4. Idea is the same.
After you will build static Qt you will need to rebuild your application. And don't copy any Qt dlls.

Adding my DLL into a Visual Studio project in C++

I am working on a project that involves making a dynamic link library, so I want to test it in a console app in Visual Studio.
The DLL is also made in Visual Studio, it doesn't have much, just a few functions in it. I'm not sure if I'm just supposed to include the librarys header in the include directories panel in Properties, or do something else
A lot of people say I'm supposed to add its corresponding .lib file in the Library or Reference directory, but I'm not sure that VS generates a .lib file alongside the DLL. I'm using VS 2015.
I don't have VS in front of me this very moment, but these should be the general steps to set it up:
Properties->Linker->Input: your.lib
Properties->Linker->Additional Library Directories: ../your/bin
Properties->General->Compiler->Additional Include Directories: ../your/include
To build your app, the DLL's API headers must be in the include for the compile-time, it's LIB files in the bin for the link-time. Once you have your app EXE, all you need is the DLL to be in the same folder as your EXE when it executes.
You might also want to add the dll project and the app project into a common solution in VS and add (right click) Project Dependency from the app to the dll. This ensures correct order of building, assuming you are going to build the dll at all.
You can also do what I did.
You can create a Libs directory inside of your Solution directory.
You can then place your .DLL files inside of the Libs directory or some sub-directory inside of Libs
In my case, I added the entire SFML-2.3.2 directory in there, which included the source-code, .lib files, and .dll files.
I did link up what I could in the project properties, but I used Visual Studio's macros to fill in the path name to the Solution directory. Just in case I wanted to put this in version control and work on it from multiple machines.
Then I opened up the Project's Property Page.
Within the property page, I went to Build Events -> Post-Build Event -> Command Line
Within the Command Line, you can add a copy command that will copy any needed files into the same directory as the executable that will need them.
In my case I used: copy "$(SolutionDir)Libs\SFML-2.3.2\bin\*" "$(TargetDir)"
I could have written multiple commands to copy just the individual files that I needed, but I had spent a good three hours trying to get SFML to work without actually installing it.

Configuring Qt Creator with executable and DLL project

I am new to QT Creator coming from Visual Studio. I have a session with two projects in it. One is a DLL with some classes that I intend to use for other purposes. The other is an executable console app that uses some of the classes from the DLL.
I currently have these two projects side by side in QT Creator. I can include the header files from the DLL in my EXE project using relative paths "../MyPrject/header.h". But how do I get QT Creator to link and then copy the DLL into the executable debug folder for debugging.
Am I doing this all wrong? Is there a better way? If it includes adding code to the .pro file, please include a link so that I can learn more.
You should make some dependencies between this projects.
opening both projects - you have done.
on editor view, right click on exe-project and select add library...
follow creator hints to add it.
2nd option: you can make subprojects. follow QtCreator: Creating Projects from documentation (help view in Qt Creator)
GwyenBleidD provided a good starting point for including DLLs.
I however, have made a habit out of modifying the .pro file directly here and honestly I prefer to modify the .pro file in the event that something goes haywire.
Suppose I wanted to use the winsock DLL.
In the .pro file, I'd first specify the .dll's corresponding .lib file:
# WinSock2 library (ws2_32.lib file)
LIBS += -lws2_32
# Path to the WinSock2 library
LIBS += -L"c:/mylibraries/"
Additionally, you'll need to specify the include path to the header files here:
INCLUDEPATH += "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/INCLUDE"
Thirdly, in my code I'd have to make sure to include the headers for it:
// I ASSUME it'll be found under something like the
// Visual Studio/VC/INCLUDE directory mentioned above.
#include <winsock2.h>
Lastly, you need to ensure that your application can find the .dll file, typically pointed to using the %PATH% environment variable.
With regards to your setup, I'd make sure that your sub-projects are configured so that the library compiles FIRST (obviously). And then ensure that the LIBS variable in your .Pro project points correctly to your .lib destination according to the build configuration (debug|release).
Qt's PRO (qmake) isn't as terrible as some make it out to be. Just give it a solid half-hour to an hour and you'll get the hang of it. I assume though that you have a solid understanding of libs and DLLs and what not.
http://qt-project.org/doc/qt-5.0/qtdoc/qmake-manual.html
The right way is to switch on CMake based project and keep exe and dll within one root project. The main benefit of this decision is IDE independent approach: you can use Qt Creator, CLion, Visual Studio without any changes in project definition. As the start point consider to see the example project https://github.com/anatoly-spb/cmake_exe_dll

Using sqlite under windows

I'm developing an app with Qt and sqlite. I had no problems while I was working under Linux, but now I have to switch to Windows for a while, and i'm stuck with a simple question.
I've downloaded the sqlite source, and compiled it with Qt as a static library. As an output, I've got three files: libsqlite.a, shell.o and sqlite3.o. I strongly believe that the libsqlite.a is my static library.
Now, I want to use it in my project. In the project directory, I've created a folder called sqlite, and put the files inside of it.
After that, I'm trying to add the library to my project. In the .pro file, I add this:
LIBS += -L"/sqlite" -l"libsqlite"
However, I keep getting an error saying:
cannot find -llibsqlite
What am I doing wrong?
"lib" prefix must be omitted.
Use the
-lsqlite
linker directive.
P.S. Another viable option is including the SQLite's sources directly to your project. There's a SQLite "amalgamation" package (only sqlite3.c and sqlite3.h files).

Qt - Get rid from .dll file missing errors

I have created a GUI which requires .dll files in order to work. Here the list of those:
mingwm10.dll libgcc_s_dw2-1.dll
QtCore4.dll QtGui4.dll
I have read that I should write
CONFIG += static
in .pro file. But it does not work. Could you help?
You need a Qt installation that is built for static-linking for that CONFIG statement to work. The only way to gt a static Qt install is to download the source package and built it yourself.
Now, to deploy your dynamically linked Qt app, just copy those DLL files to the same folder as your built exe file. This may be easier than building Qt statically.