Hi all.
Have created C Library code of a Matlab function which compiles under Qt fine:
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-27T19:09:07
#
#-------------------------------------------------
QT -= gui
CONFIG += staticlib
TARGET = KalmanFilter
TEMPLATE = lib
DEFINES += KALMANFILTER_LIBRARY
SOURCES += \
rtGetNaN.c \
rtGetInf.c \
rt_nonfinite.c \
kalmanfilter.c \
kalmanfilter_terminate.c \
kalmanfilter_initialize.c \
kalmanfilter_data.c
HEADERS += \
rtwtypes.h \
rtGetNaN.h \
rtGetInf.h \
rt_nonfinite.h \
kalmanfilter.h \
kalmanfilter_types.h \
kalmanfilter_terminate.h \
kalmanfilter_initialize.h \
kalmanfilter_data.h
INCLUDEPATH += "/home/david/Development/Matlab/kaltest/coderdemo_kalman_filter" \
/home/david/Matlab/toolbox/shared/simtargets \
/home/david/Matlab/extern/include \
/home/david/Matlab/simulink/include
target.path = /usr/lib
INSTALLS += target
OTHER_FILES +=
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-27T19:09:07
#
#-------------------------------------------------
QT -= gui
CONFIG += staticlib
TARGET = KalmanFilter
TEMPLATE = lib
DEFINES += KALMANFILTER_LIBRARY
SOURCES += \
rtGetNaN.c \
rtGetInf.c \
rt_nonfinite.c \
kalmanfilter.c \
kalmanfilter_terminate.c \
kalmanfilter_initialize.c \
kalmanfilter_data.c
HEADERS += \
rtwtypes.h \
rtGetNaN.h \
rtGetInf.h \
rt_nonfinite.h \
kalmanfilter.h \
kalmanfilter_types.h \
kalmanfilter_terminate.h \
kalmanfilter_initialize.h \
kalmanfilter_data.h
INCLUDEPATH += "/home/david/Development/Matlab/kaltest/coderdemo_kalman_filter" \
/home/david/Matlab/toolbox/shared/simtargets \
/home/david/Matlab/extern/include \
/home/david/Matlab/simulink/include
target.path = /usr/lib
INSTALLS += target
OTHER_FILES +=
To copy to clipboard, switch view to plain text mode
The library (when "make" then "sudo make install") successfully compiles and installs to /usr/lib
However, when I try to utilise in another Qt application, it the compile fails as follows:
testclass.o: In function `TestClass':
/home/david/Development/Qt/GenTest/testclass.cpp:12: undefined reference to `kalmanfilter_initialize()'
testclass.o: In function `TestClass::run()':
/home/david/Development/Qt/GenTest/testclass.cpp:22: undefined reference to `kalmanfilter(double const*, double*)'
collect2: ld returned 1 exit status
make: *** [GenTest] Error 1
10:23:56: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project GenTest (kit: Desktop Qt 5.1.0 GCC 64bit)
When executing step 'Make'
testclass.o: In function `TestClass':
/home/david/Development/Qt/GenTest/testclass.cpp:12: undefined reference to `kalmanfilter_initialize()'
testclass.o: In function `TestClass::run()':
/home/david/Development/Qt/GenTest/testclass.cpp:22: undefined reference to `kalmanfilter(double const*, double*)'
collect2: ld returned 1 exit status
make: *** [GenTest] Error 1
10:23:56: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project GenTest (kit: Desktop Qt 5.1.0 GCC 64bit)
When executing step 'Make'
To copy to clipboard, switch view to plain text mode
The application looks as follows:
PRO File
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-23T16:47:17
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = GenTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += \
main.cpp \
testclass.cpp
HEADERS += \
testclass.h
LIBS += -L/usr/lib -lKalmanFilter
INCLUDEPATH += $$PWD/../KalmanFilter
DEPENDPATH += $$PWD/../KalmanFilter
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-23T16:47:17
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = GenTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += \
main.cpp \
testclass.cpp
HEADERS += \
testclass.h
LIBS += -L/usr/lib -lKalmanFilter
INCLUDEPATH += $$PWD/../KalmanFilter
DEPENDPATH += $$PWD/../KalmanFilter
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QCoreApplication>
#include "testclass.h"
int main(int argc, char *argv[])
{
TestClass *tc = new TestClass();
tc->run();
return a.exec();
}
#include <QCoreApplication>
#include "testclass.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TestClass *tc = new TestClass();
tc->run();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Class Header
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <QObject>
#include "kalmanfilter.h"
{
Q_OBJECT
public:
explicit TestClass
(QObject *parent
= 0);
void run();
signals:
public slots:
private:
real_T z[2];
real_T y[2];
};
#endif // TESTCLASS_H
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <QObject>
#include "kalmanfilter.h"
class TestClass : public QObject
{
Q_OBJECT
public:
explicit TestClass(QObject *parent = 0);
void run();
signals:
public slots:
private:
real_T z[2];
real_T y[2];
};
#endif // TESTCLASS_H
To copy to clipboard, switch view to plain text mode
Class File
#include "testclass.h"
#include "kalmanfilter.h"
#include "kalmanfilter_initialize.h"
#include "kalmanfilter_data.h"
#include "kalmanfilter_terminate.h"
#include <QDebug>
TestClass
::TestClass(QObject *parent
) :{
kalmanfilter_initialize();
}
void TestClass::run()
{
for (real_T r1 = 0; r1 < 10; r1++)
{
z[0] = r1;
z[1] = r1;
kalmanfilter(z,y);
qDebug() << "Z = " << z[0] << "," << z[1];
qDebug() << "Zest = " << y[0] << "," << y[1];
}
}
#include "testclass.h"
#include "kalmanfilter.h"
#include "kalmanfilter_initialize.h"
#include "kalmanfilter_data.h"
#include "kalmanfilter_terminate.h"
#include <QDebug>
TestClass::TestClass(QObject *parent) :
QObject(parent)
{
kalmanfilter_initialize();
}
void TestClass::run()
{
for (real_T r1 = 0; r1 < 10; r1++)
{
z[0] = r1;
z[1] = r1;
kalmanfilter(z,y);
qDebug() << "Z = " << z[0] << "," << z[1];
qDebug() << "Zest = " << y[0] << "," << y[1];
}
}
To copy to clipboard, switch view to plain text mode
Many thanks in advance
Bookmarks