You are not logged in.

#1 2016-07-13 07:57:17

fusion809
Member
Registered: 2015-06-19
Posts: 70

QCustomPlot error: cannot find QObject header

Hi,

I have been trying to compile this C++ file:

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>
#include <utility>
#include <unistd.h>
#include <qcustomplot.h>

using namespace std;

double dx2(double t, double x, double dx)
{
	return {-9.8*cos(x)};
}

std::pair<double, double> RK4(double t, double x, double dx, double h)
{
	// k values are diffs in dy/dx.
	// l values are diffs in x.
	double k1, k2, k3, k4, l1, l2, l3, l4, diff1, diff2;
	k1 = h*dx2(t,x,dx);
	l1 = h*dx;
	k2 = h*dx2(t+h/2,x+l1/2,dx+k1/2);
	l2 = h*(dx+k1/2);
	k3 = h*dx2(t+h/2,x+l2/2,dx+k2/2);
	l3 = h*(dx+k2/2);
	k4 = h*dx2(t+h,x+l3,dx+k3);
	l4 = h*(dx+k3);
    diff1 = (l1+2*l2+2*l3+l4)/float(6); // diff in x.
    diff2 = (k1+2*k2+2*k3+k4)/float(6); // diff in y.
    return {diff1, diff2};
}

int main()
{
    double N     = 1000.0;
    double t0    = 0.0;
    double t1    = 10.0;
    double x0    = 0.0;
    double dx0   = 0.0;
    double h     = (t1 - t0) / double(N);
    std::vector<double> t;
    t.push_back(t0);
    std::vector<double> x;
    x.push_back(x0);
    std::vector<double> dx;
    dx.push_back(dx0);

    ofstream myfile;
    myfile.open("example.txt");

    for(int i = 1; i<=N; i++) {
        auto diff = RK4(t[i-1],x[i-1],dx[i-1],h);
        t.push_back(  t[i-1] + h);
        x.push_back(  x[i-1] + diff.first  );
        dx.push_back(dx[i-1] + diff.second );
        myfile << "\nt is " << t[i-1];
        myfile << "; x is " << x[i-1];
        usleep(1000);
    }
    myfile.close();
    plot(t,x);
    
    return 0;
}

with the qcustomplot.h header provided by the qcustomplot-qt5 AUR package. This gives the compilation error (in Geany, I know the first line is Geany's attempt at compiling example.cpp and producing the example binary):

g++ -Wall -o "example" "example.cpp" (in directory: /home/fusion809/Documents/CodeLite/firstExample)
In file included from example.cpp:8:0:
/usr/include/qcustomplot.h:29:19: fatal error: QObject: No such file or directory
 #include <QObject>
                   ^
compilation terminated.
Compilation failed.

In my efforts to fix this issue I ran:

find /usr/include -iname "qobject"

and this returned:

/usr/include/qt/QtCore/QObject
/usr/include/qt4/QtCore/QObject

so I edited my /usr/include/qcustomplot.h file, changing:

#include <QObject>

to

#include <qt/QtCore/QObject>

But then compiling example.cpp again gave:

g++ -Wall -o "example" "example.cpp" (in directory: /home/fusion809/Documents/CodeLite/firstExample)
In file included from /usr/include/qt/QtCore/QObject:1:0,
                 from /usr/include/qcustomplot.h:29,
                 from example.cpp:8:
/usr/include/qt/QtCore/qobject.h:46:32: fatal error: QtCore/qobjectdefs.h: No such file or directory
 #include <QtCore/qobjectdefs.h>
                                ^
compilation terminated.
Compilation failed.

I would rather not edit files provided by my core Qt packages, so any ideas of what I need to do to fix this header issue?

Thanks for your time,
Brenton

Offline

#2 2016-07-13 09:44:58

fusion809
Member
Registered: 2015-06-19
Posts: 70

Re: QCustomPlot error: cannot find QObject header

Never I worked around it with this new make file:

all:
	/usr/bin/g++ -Wall -fPIC -o "example" "example.cpp" -I/usr/include/qt -I/usr/include/qt/QtCore -I/usr/include/qt/QtGui -I/usr/include/qt/QtWidgets
clean:
	rm example

it makes the include locations of these header files more accessible.

Offline

Board footer

Powered by FluxBB