Using sqlite under windows - c++

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).

Related

build c++ (qt) program as one portable file with built-in dependences

I have a Qt project. I can build it but I have to keep all external files near with the executable one if I want to use the exe-file as portable program. But a customer wants it to be an one executable without any other files. The size of result file does not matter.
So, if I would use Python, I could do it like this:
[localhost#localhost ~]$ pyinstaller --onefile myscript.py
Can I do the same using Qt (with MinGW)?
It depends on the files you are talking about. With static linking you can get rid of dll files and by using Qt resource collection files you can for example link pictures and html files into your executable.
You could package your bundle into a self-extracting ZIP that automatically runs and cleans up after itself. I found this answer that gets you close.
You can't unless you have a commercial Qt license or if you don't link to any of the Qt libraries (you could still use Qt creator and qmake).

How exactly compile sqllite app in Code Blocs on Windows in c++

(My first question)
I have no idea how i can compile and link my project in Code Blocs on Windows in c++ properly. I included and i set up it's localization in compiler options. I assume that i need to link any library. I read that it can by sqlite(3?).lib but in all downloadable files on sqlite project site is only .dll
huge thx for help
The suggested way of using the SQLite library is to embed it directly in your application, i.e., download the amalgamation source code, and just add the sqlite3.c and .h files to your project in the sample place where you have the other source files.
Also how build sqlite lib , how to use def files

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.

Qt - How to build a standalone app with OpenCV and Qt

I was able to connect Qtwith OpenCV and the my application is working properly. But now would like that my .exe file does not have any dependencies with .dll files. I would like be able to use my application in another computer without concerns.
I tried to search in several forums but i didnĀ“t find any solution to my problem.
Adding CONFIG += static to my .pro file is enough??
You need to add the CONFIG += static indeed, besides that you need to create a static build of OpenCV, Qt, and statically link it all into an exe.
I shared my setup here.
Just clone the repo and follow the instructions :)
check out bin2h. it can convert your dll file to a header file that you import into your project. you can then write out to file the generated header and then dynamically link it to your executable

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