Probleme mit eigener Bibliothek
Verfasst: 14. Mai 2012 14:45
Da mittlerweilen das Programm zur Vektoraddition mit QVector gut funktioniert,
habe ich mir gedacht, ich könnte vielleicht eine eigene Bibliothek für Vektorberechnungen und später für Matrixoperationen anlegen, aber es gab da gleich eine Menge Fehlermeldungen. Zuerst habe ich ein neues Qt4-Projekt mit dem Namen Vektor_Bibliothek angelegt, dort die die Klasse MatDemo
eingefügt und die Datei Vektor_Bibliothek.pro umgeändert in
TEMPLATE=lib
DEPENDPATH+=.
INCLUDEPATH+=.
CONFIG+=dll qt thread
DEFINES+=BUILD_DLL
HEADERS += matdemo.h
SOURCES += matdemo.cpp
und dann alles kompiliert. Dann gab es folgende Fehlermeldungen.
/Qt_Beispiele/Vektor_Bibliothek/matdemo.h:1: error: unterminated #ifndef
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: ‘MatDemo’ has not been declared
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: ISO C++ forbids declaration of ‘MatDemo’ with no type
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: only constructors take base initializers
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:8: error: ‘MatDemo’ is not a class or namespace
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:9: error: ‘_v1’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:9: error: ‘_v2’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: expected ‘,’ or ‘;’ before ‘for’
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: ‘i’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: expected ‘;’ before ‘)’ token
Hernach habe ich noch ein leeres Qt4-Projekt mit dem Namen Test_Bibliothek_Main angelegt dort die folgende Quelldatei
untergebracht und die Datei Test_Bibliothek_Main.pro umgeändert in
TEMPLATE=app
TARGET=MatDemo
DEPENDPATH+=.
INCLUDEPATH+=.
LIBS+=/home/...s/Qt_Beispiele/libdynamicLib.a
SOURCES += main.cpp
Dies ergab folgende Fehlermeldungen.
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:1: error: home/....s/Qt_Beispiele/dynamicLib/Vektor_Bibliothek/matdemo.h: Datei oder Verzeichnis nicht gefunden
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:26: error: ‘MatDemo’ was not declared in this scope
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:26: error: expected ‘;’ before ‘demo’
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:28: error: ‘demo’ was not declared in this scope
Kann mir jemand mitteilen, was ich ändern muß? In meinem Buch zu Qt steht hierüber fast gar nichts.
habe ich mir gedacht, ich könnte vielleicht eine eigene Bibliothek für Vektorberechnungen und später für Matrixoperationen anlegen, aber es gab da gleich eine Menge Fehlermeldungen. Zuerst habe ich ein neues Qt4-Projekt mit dem Namen Vektor_Bibliothek angelegt, dort die die Klasse MatDemo
Code: Alles auswählen
#ifndef MATDEMO_H
#define MATDEMO_H
#ifndef BUILD_DLL
#define EXPORT_DLL
#include <QVector>
class EXPORT_DLL MatDemo:public QObject
{
QOBJECT
public:
MatDemo(const QVector<double> &v1, const QVector<double> &v2);
{
}
~MatDemo(const QVector<double> &v1, const QVector<double> &v2);
{
}
void addiereVec(QVector<double> &result);
private:
QVector<double>_v1;
QVector<double>_v2;
};
#endif // MATDEMO_H
#include "matdemo.h"
#include <QObject>
#include <iostream>
MatDemo::MatDemo(const QVector<double> &v1, const QVector<double> &v2) : _v1(v1), _v2(v2)
{
}
void MatDemo::addiereVec(QVector<double> &result)
{int M=qMin(_v1.size(),_v2.size())
for(int i=0;i<5;i++)
{
result.push_back(_v1[i]+_v2[i]);
std::cout<<" result[i]="<<result[i]<<" _v1[i]="<<_v1[i]<<std::endl;
}
}
TEMPLATE=lib
DEPENDPATH+=.
INCLUDEPATH+=.
CONFIG+=dll qt thread
DEFINES+=BUILD_DLL
HEADERS += matdemo.h
SOURCES += matdemo.cpp
und dann alles kompiliert. Dann gab es folgende Fehlermeldungen.
/Qt_Beispiele/Vektor_Bibliothek/matdemo.h:1: error: unterminated #ifndef
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: ‘MatDemo’ has not been declared
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: ISO C++ forbids declaration of ‘MatDemo’ with no type
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:5: error: only constructors take base initializers
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:8: error: ‘MatDemo’ is not a class or namespace
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:9: error: ‘_v1’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:9: error: ‘_v2’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: expected ‘,’ or ‘;’ before ‘for’
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: ‘i’ was not declared in this scope
/Qt_Beispiele/Vektor_Bibliothek/matdemo.cpp:10: error: expected ‘;’ before ‘)’ token
Hernach habe ich noch ein leeres Qt4-Projekt mit dem Namen Test_Bibliothek_Main angelegt dort die folgende Quelldatei
Code: Alles auswählen
#include "home/....s/Qt_Beispiele/dynamicLib/Vektor_Bibliothek/matdemo.h"
#include <QApplication>
#include <QtCore/QCoreApplication>
#include <iostream>
#include <QVector>
int main(int argc, char *argv[])
{ typedef QVector<double> vec;
QCoreApplication a(argc, argv);
double x[5]={1.1,2.2,3.3,4.4,5.5};
double y[5]={2.2,4.4,6.6,8.8,11.0};
QVector<double>v1;
;
for(int i=0;i<5;i++)
{v1.push_back(x[i]);
}
vec v3;
v3.push_back(9.99);
QVector<double> v2;
for(int i=0;i<5;i++)
{v2.push_back(y[i]);
v3.push_back(y[i]);
std::cout<<" i="<<i<<" v1="<<v1[i]<<" x[i]="<<x[i]<<" v3="<<v3[i]<<std::endl;
}
MatDemo demo(v1,v2);
QVector<double> result;
demo.addiereVec(result);
for(int i=0;i<result.size();i++)
{
std::cout<<" result[i]="<<result[i]<<std::endl;
}
return a.exec();
}
TEMPLATE=app
TARGET=MatDemo
DEPENDPATH+=.
INCLUDEPATH+=.
LIBS+=/home/...s/Qt_Beispiele/libdynamicLib.a
SOURCES += main.cpp
Dies ergab folgende Fehlermeldungen.
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:1: error: home/....s/Qt_Beispiele/dynamicLib/Vektor_Bibliothek/matdemo.h: Datei oder Verzeichnis nicht gefunden
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:26: error: ‘MatDemo’ was not declared in this scope
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:26: error: expected ‘;’ before ‘demo’
/Qt_Beispiele/Test_Bibliothek_Main/main.cpp:28: error: ‘demo’ was not declared in this scope
Kann mir jemand mitteilen, was ich ändern muß? In meinem Buch zu Qt steht hierüber fast gar nichts.