QtCreator LNK2019 error with external library - c++

I have a problem when I want to link a library to my Qt project.
When I try to include an external library (libnodave.lib) in Qt Creator and try to build it, the following error occurs.
main.obj:-1: Fehler: LNK2019: unresolved external symbol __imp_daveSetDebug referenced in function main
I'm pretty sure that I included all needed files in my project and the .pro file. I used the "Add Library" wizard to add the library.
After no success with Qt Creator, I created a minimal example with Visual Studio. When I include all the needed files to the VS project, I can build and run it without errors. So I think that there must be a problem with Qt Creator linking the library. I also tried the Qt-Visual-Studio-Add-in, but there, the same error occurs.
Here are my minimal examples with the library I want to include.
In the Visual Studio example, I added the library path, the include path, and the name of the library to the project properties. It works.
I hope you can help me with my problem.
EDIT:
I want to use the library to get some data from a S7-300 SPS device.
The following code is the minimal example from Qt Creator.
#include <QCoreApplication>
#include <QDebug>
#include <nodave.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
daveInterface *di;
daveSetDebug(daveDebugConnect); // Function of libnodave Library
qDebug() << "Hello World";
return a.exec();
}
This is the whole code from the Visual Studio minimal example.
#include "stdafx.h"
#include <nodave.h>
int _tmain(int argc, _TCHAR* argv[])
{
daveInterface *di;
daveSetDebug(daveDebugConnect);
printf("Hello World\n");
return 0;
}
The code is very small, so I don't think that there is an error inside.
That's why I think it must be a problem with the Qt linker or something like that.
EDIT:
My .pro file.
QT += core
QT -= gui
TARGET = qtminimal
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32: LIBS += -L$$PWD/../libnodave-0.8.5/win/ -llibnodave
INCLUDEPATH += $$PWD/../libnodave-0.8.5
DEPENDPATH += $$PWD/../libnodave-0.8.5

The problem was that the Qt project is 64bit and the library I want to include is only 32bit.
So I downloaded the 32bit version of Qt and now it works.
I found the mistake, when I tried to build only the minimal example with libnodave, without any 64bit Qt libraries.
By creating a new Qt project in VS2013, with this workaround and adding the libnodave library afterwards I could change whether it should be a 64bit or 32bit build. By choosing the 32bit build, the Qt library creates errors but not the libnodave lib. When I choose 64bit build, only libnodave creates the errors.
I hope it is useful for someone else.

Related

How to compile a Qt program without qtCreator on Windows?

I have read the question Can I use Qt without qmake or Qt Creator? which is basically the same for Linux, and very useful.
How to compile a basic program using QtCore (console application, even without GUI) on Windows, without using qmake or qtCreator IDE, but just the Microsoft VC++ compiler cl.exe?
For example, let's say we have:
#include <iostream>
#include <QtCore>
int main()
{
QVector<int> a; // Qt object
for (int i=0; i<10; i++)
a.append(i);
std::cout << "hello";
return 0;
}
Using:
call "C:\path\to\vcvarsall.bat" x64
cl main.cpp /I D:\coding\qt\qtbase-everywhere-src-5.15.5\include
fails with:
D:\coding\qt\qtbase-everywhere-src-5.15.5\include\QtCore\QtCore(3): fatal error C1083: Cannot open include file: 'QtCore/QtCoreDepends': No such file or directory
Indeed this file is not present in the release qtbase-everywhere-opensource-src-5.15.5.zip from https://download.qt.io/archive/qt/5.15/5.15.4/submodules/.
TL;DR: More generally, which cl.exe arguments should we use to to able to use all Qt includes, and effectively compile such a minimal project using QtCore?
I finally managed to do it 100% from command line, without the qtCreator IDE, but not yet without qmake. Steps to reproduce:
Let's assume Microsoft MSVC 2019 is installed.
Install qt-opensource-windows-x86-5.14.2.exe. (This is the latest Windows offline installer I could find), double check that you install at least msvc2017_64.
Note: Don't use qtbase-everywhere-opensource-src-5.15.4.zip: using the include subfolder from this package for cl.exe /I ... is not enough. (I thought it would, at first)
Create a folder example containing the main.cpp file above
Open a command line window in this folder and do:
vcvarsall.bat x64
Now either do "c:\path\to\msvc2017_64\bin\qmake.exe" -project to create a example.pro project file or create it manually with:
TEMPLATE = app
TARGET = qt_example
INCLUDEPATH += .
CONFIG += console
SOURCES += main.cpp
Do "c:\path\to\msvc2017_64\bin\qmake.exe". This will create a Makefile file.
Run nmake. This is Microsoft MSVC's equivalent of the make tool.
Copy c:\path\to\msvc2017_64\bin\Qt5Core.dll into the release folder
Run release\example.exe. Working!
Addendum: here is solution now for a minimal GUI app:
main.cpp
#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QMessageBox>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMessageBox::information(NULL, "Hello", "Hello", "Ok");
return a.exec();
}
qt_example_gui.pro
TEMPLATE = app
TARGET = qt_example_gui
INCLUDEPATH += .
SOURCES += main.cpp
QT += gui widgets
Do the vcvarsall.bat x64, qmake, nmake like in the solution above. No be sure you have this file structure:
release\qt_example_gui.exe
release\Qt5Core.dll
release\Qt5Gui.dll
release\Qt5Widgets.dll
release\platforms\qwindows.dll
Run the .exe, that's it!

Run Wt Framework in Qt Creator

I'm just trying to run an example from https://www.webtoolkit.eu/wt
I have downloaded precompiled binaries from https://github.com/emweb/wt/releases
I choose "Wt-4.3.1-msvs2017-Windows-x64-SDK.zip" and extracted into a folder.
Kit i use: Qt 5.12.0 MSVC 2017 x64
Then i added into my Qt project .pro file next lines:
LIBS += -L"C:/wt/lib"
INCLUDEPATH += C:/wt/include
In main.cpp i added the next code:
#include <Wt/WApplication.h>
#include <Wt/WServer.h>
int main(int argc, char *argv[])
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env){
auto app = std::make_unique<Wt::WApplication>(env);
return app;
});
}
When i try to run this stuff i get an error (127 errors): LNK 2001, LNK 2019, LNK 1120
Here is screenshot of the errors and source
.pro file
I think you need to specify which libs you need to link with explicitly. Check out: How to add additional libraries to Visual Studio project?

Error accessing GStreamer Library in Qt C++ - Program excited with code 0xc0000135 when Debugging

I want to use gstreamer library for video programming and I read that Qt5.5.0 provided support for gstreamer-1.0, which is the library I use. I downloaded firstly version 1.0.7, but I got the following error, so I downloaded the latest version 1.5.2, which I am trying to use now.
I managed to link the gstreamer library header files, so I didn't build it, but just include its path and access the header files and libs. Anyway, now I have an error of The program has unexpectedly finished. When I try to debug it, I get the following error in a pop-up:
During startup program excited with code 0xc0000135.
On General Messages:
:1:24: Reading only version 1.1 parts.
:10:5: Expected only Component and ModuleApi object definitions.
I read many questions related to this error, but none helped, I think is an error with the gstreamer library, but may be a compiler/debugger error too, as I read in some threads.
I checked my PATH variable, as I also can not run the program outside Qt (by trying to run the .exe in debug folder of the build) - the error : library Qt5Cored.dll missing - and I found this paths:
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\lib;
C:\Users\user\Documents\build-GStreamer-test5-Desktop_Qt_5_5_0_MinGW_32bit-Debug;
C:\Qt\Qt5.5.0_Android\5.5\mingw492_32\bin;
C:\Qt\Qt5.5.0_Android\Tools\mingw492_32\bin;
C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0;
C:\Program Files\Skype\Phone\ (I dont know why is this included, but it was there when I checked )
I am relatively new to Qt, and never encountered this error before. If you need any code:
.pro:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = GStreamer-test5
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:/gstreamer/1.0/x86/include/gstreamer-1.0
C:/gstreamer/1.0/x86/lib/gstreamer-1.0/include
C:/gstreamer/1.0/x86/include/glib-2.0
C:/gstreamer/1.0/x86/lib/glib-2.0/include
LIBS += -L C:/gstreamer/1.0/x86/lib/ -lgstreamer-1.0
and .main:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <stdio.h>
#include "gst/gst.h"
void *__gxx_personality_v0;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
const gchar *nano_str;
guint major, minor, micro, nano;
gst_init (&argc, &argv);
gst_version (&major, &minor, &micro, &nano);
if (nano == 1)
nano_str = "(CVS)";
else if (nano == 2)
nano_str = "(Prerelease)";
else
nano_str = "";
// printf ("This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str);
qDebug() << "This program is linked against GStreamer %d.%d.%d %s\n", major, minor, micro, nano_str ;
return a.exec();
Firstly, I had the error :
undefined reference to `__gxx_personality_v0' , but fixed it by adding *void __gxx_personality_v0; , although I don't know what excatly it is.
Its been three days I struggle with this problem. Any help appreciated, or maybe if you can help me by some code on how to access the header files and libs, or how the configuration of the debugger options / PATH must be.
I am using Qt5.5.0 for Android, for Windows I use MinGW 4.9.2 32 bit compiler and GNU gdb 7.8 as debugger.
Thanks in advance!
I had similar problems in my project that was using both Qt and Gstreamer.
The сause of "undefined reference to `__gxx_personality_v0'" error is that Qt and GStreamer for windows from official sites were built using different compilers and their libstdc++ libraries are not compatible - they are using different exception handling methods.
In fact, GStreamer is pure C library. The only component of it that was written in C++ is taglib library. If you will build this lib from sources using your MinGW compiler, and then replace it in the GStreamer folder, the problem of incompatibility will be solved.
In more detail you can read here: https://github.com/knowthelist/knowthelist.
I managed to solve the above problem. I had to include in the .exe folder (the build-debug folder) all the dlls included, so I tried to run the .exe from there, not run it from Qt, and some errors with dlls missing gave me the names of the dlls. I found some in my library bin folder and some downloaded, and now everything seems fine :)

SYSTEMTIME in qt

I am a bit stuck at the moment with a little sample project that I would like to run to test some cryptology that I want to use in a main project.
Basically I am using the latest Qt Creator and I have created a simple window dialog. Furthermore, I would like to test the PBKDF2 implementation through CkCrypt2
So what I have done is downloading the X64 version of the library and added it to my project folder. I then told my Qt project to use an external library, the final .pro file looks like this:
#-------------------------------------------------
#
# Project created by QtCreator 2013-06-09T18:09:44
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = crypt2test
TEMPLATE = app
SOURCES += main.cpp\
m
ainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64d
else:unix: LIBS += -L$$PWD/libs/ -lChilkatDbgDll_x64
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include
I can successfully load the library but I cannot start the application.
My mainwindow.cpp looks like this:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "CkCrypt2.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
CkCrypt2 crypt;
bool success;
success = crypt.UnlockComponent("Just some random text ");
if ( !success )
{
qDebug() << "Not successfully unlocking the library";
}
}
MainWindow::~MainWindow()
{
delete ui;
}
The error message I get in the compiler is:
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:127: error: C2061: syntax error : identifier 'SYSTEMTIME'
c:\qt\qt5.0.2\tools\qtcreator\bin\crypt2test\include\CkString.h:129: error: C2061: syntax error : identifier 'SYSTEMTIME'
C:\Qt\Qt5.0.2\Tools\QtCreator\bin\crypt2test\include\CkCrypt2.h:429: error: C2061: syntax error : identifier 'SYSTEMTIME'
Looking into the files I see:
void appendDateRfc822(SYSTEMTIME &sysTime);
void appendDateRfc822Gmt(SYSTEMTIME &sysTime);
// GETSIGNATURESIGNINGTIME_BEGIN
bool GetSignatureSigningTime(int index, SYSTEMTIME &outSysTime);
// GETSIGNATURESIGNINGTIME_END
Okay, so it is complaining about the SYSTEMTIME construct. So I look up the error C2061
Basically it says:
The compiler found an identifier where it wasn't expected. Make sure
that identifier is declared before you use it.
Which makes sense, so I look up the SYSTEMTIME and try to do :
#include <windows.h>
But that leads to many more errors in the windows.h file itself.
I use the MS Visual C++ compiler in Qt. Even though I use qmake. I am very new to this and I do not understand it all yet. Furthermore, I have no idea how to fix this, because including the windows.h does not help.
What seems to be the problem here ? Is this an issue regarding my compiler or the constulation that I use a third party app which library is compiled with MS Visual C++ and I am now trying to use this on my Windows machine in Qt with a Windows Visual C++ compiler ?
For any help I am gratefully thankful!
EDIT1:
Actually, after a clean all and qmake and build project I have now different errors and none were found in the Windows.h as previously stated. Since there were so many I have made a screenshot: http://i.imgur.com/B8EoENB.png
EDIT2:
I have adjusted the library that I include. Before this I was using the multi-threaded library of CkCrypt in the Debug mode. I have now included the single realease library. Which is located in the same directory.
When including windows.h I got the errors that things were already defined. So I removed the line again. With this result: http://i.imgur.com/z415txR.png
This shows at the bottom that MSVCRT conflichts with other library. It mentions to use NODEFAULTLIB:library but I am not to sure how to do that. Will google and keep this up to date as I process.
Many years ago, Chilkat was originally developed for the Windows platform only, and used SYSTEMTIME for this reason. In the last 5 years (approx) Chilkat is cross-platform, and SYSTEMTIME no longer makes sense. To cope with the issue, there is a "SystemTime.h" header in the same directory as the CkCrypt2.h header file. You could include this to solve the problem. (However, if WIN32 is defined, you'll probably need to edit SystemTime.h to remove the #ifdef.)
In any case, the methods using SYSTEMTIME are going to be deprecated. For any method or property that uses SYSTEMTIME, there should be a newer alternative method/property that instead uses CkDateTime.
Finally, Chilkat will test with Qt so that for the next version, (hopefully) Qt out-of-the-box will compile without any pitfalls.

Linking Qt in CodeLite

I'm not sure why this is, but 99% of the problems I have with programming in C++ have to do with the gcc linker.
I want to link the Qt library to a project in CodeLite. This is the code I have so far:
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
When I compile, I get the error
/Users/andrew/Dev/C++/COSC 102/elitecod/main.cpp:1:24: error: QApplication: No such file or directory
I have Qt installed (with Homebrew, Mac OS X Lion) in /usr/local/include. Why is this happening, and how can I fix this problem?
The error indicates it can't find the file QApplication. You need to add the Qt 'include' directory to the list of places the compiler should look for it and other header files.
A brief google seems to indicate you may have other problems with Qt, you might want to keep this link handy.