Qt creator "Undefined reference" to external C library - c++

I've read all other answers and try to follow but still got the error.
I use Qt 4.8.6 and QT creator 3.5.1. I include libproj in the .pro file:
INCLUDEPATH += C:/Qt/include/libproj-4.4
LIBS += -LC:/Qt/lib -lproj
The libproj.a is available in the specified dir, and src code is also available.
The header file is included in Projection.h:
extern "C" {
#include <proj_api.h>
}
The function "pj_free" is called in Projection_libproj.cpp
Then I got the error:
C:\Users\ngu\Documents\jan-mayen\JanMaven\src\map\Projection_libproj.cpp:-1: error: undefined reference to `pj_free'

Related

How can I use taglib in Qt?

After downloading taglib (version 1.11.1) from taglib.org, I built it with cmake and got a .dll and a .dll.a file. Then I brought taglib folder to where my Qt project folder is in and named it 'myTaglib' as this picture
When I go to 'myTaglib' folder, I'll get these items
Now jumping into .pro file, I tried to link to taglib:
QT += quick multimedia core
CONFIG += c++11
INCLUDEPATH += $$PWD/myTaglib
DEPENDPATH += $$PWD/myTaglib
LIBS += -L$$PWD/myTaglib -llibtag
And in header file, I included necessary files and using namespace TagLib like this:
#include <tag.h>
#include <fileref.h>
#include <mpeg/id3v2/id3v2tag.h>
#include <mpeg/mpegfile.h>
#include <mpeg/id3v2/id3v2frame.h>
#include <mpeg/id3v2/id3v2header.h>
#include <mpeg/id3v2/frames/attachedpictureframe.h>
using namespace TagLib;
After all, I built my project and got some errors:
...
undefined reference to `__imp__ZN6TagLib8FileNameC1EPKc' in player.cpp - line 94
undefined reference to `__imp__ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE' in player.cpp - line 94
undefined reference to `__imp__ZNK6TagLib7FileRef3tagEv' in player.cpp - line 95
undefined reference to `__imp__ZNK6TagLib6String10toCWStringEv' in player.cpp - line 97
undefined reference to `__imp__ZNK6TagLib6String10toCWStringEv' in player.cpp - line 96
...
Then, I checked these lines but it didn't show something like underlined error or red text or something like that, you can see this picture
As a newbie in Qt, I'm really confused with these errors. I hope you guys can enlighten my mind and help me deal with this problem. Thank you so much
The actual name of the library is "tag", so you just have to change the lib name.
LIBS += -L$$PWD/myTaglib/ -ltag

Undefined reference errors linking a dll in QtCreator

I have built a simple dll using g++ under mingw:
We have an include file:
#ifndef __TESTDLL_H
#define __TESTDLL_H
class sineCalculator
{
double n;
public:
sineCalculator();
sineCalculator(double);
double sine();
void setAngle(double);
};
#endif
Then an implementation cpp:
#include <testdll.h>
#include <math.h>
sineCalculator::sineCalculator()
{
n = 0;
}
sineCalculator::sineCalculator(double x)
{
n = x;
}
double sineCalculator::sine()
{
return sin(n);
}
void sineCalculator::setAngle(double x)
{
n = x;
}
This I have compiled as a dll.producing both a .dll file and .a import library with the names visaTest.dll and libvisaTest.a
I can write a small program and link to this dll successfully just using the command line - no Qt just g++. I can create objects and run the methods all fine.
However, I now want to add this library to a Qt application within QtCreator. I have followed the advice of several questions and added these lines to my .pro file:
INCLUDEPATH += C:/msys64/home/hoyla/libs/
INCLUDEPATH +=C:/msys64/home/hoyla/includes/
DEPENDPATH +=C:/msys64/home/hoyla/libs/
win32:CONFIG(release, debug|release): LIBS += -LC:/msys64/home/hoyla/libs/ -lvisaTest
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/msys64/home/hoyla/libs/ -lvisaTest
else:unix: LIBS += -L$$PWD/../../../../libs/ -lvisaTest
Although I use some absolute paths here I have also tried with relative paths. However, I keep getting undefined reference errors to my dll functions when building the Qt file. I would point out that the paths point to the location of my .a import library, the .dll itself is within the system path. What am I doing wrong here?
Mea Culpa! It seems I had compiled my library under 64-bit MinGW but Qt Creator was defaulting to the 32-bit toolchain. One would have thought that the linker might have been able to determine that was the error and generate a more useful error message but there we go. Lesson learned - make sure you're using the tools you think you're using.

How to use libltdl on OS X in a Qt project

I try to use libltdl in Qt on OSX. I downloaded the library with brew and i can find it in /usr/local/lib/libltdl.dylib .
I link it in Qt Creator using the assistant and those lines were added to my .pro
macx: LIBS += -lltdl
The problem is when i use :
#include <ltdl.h>
the app doesn't compile and the following error appears :
fatal error: 'ltdl.h' file not found
#include <ltdl.h>
Thanks for your help !

QtCreator LNK2019 error with external library

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.

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.