C++ GNU Plot

ruzne programy,konverze dat, digitalizace, atd...
Odpovědět
Uživatelský avatar
zz912
Příspěvky: 1348
Registrován: 25. 5. 2008, 7:16

4. 9. 2020, 10:33

Zdravím,

chtěl jsem přejít z Arduina na Raspberry PI 3b. Místo Arduino IDE jsem chtěl používat Geany.
Už jsem přišel na to jak svůj program přepsat z jazyka Wirring na c++, ale už tři dny jsem se zasekl na tom jak nahradit sériový Plotter, nebo jak vykreslovat data. Dle diskuzí na netu by šlo použít GNU plot.

V příkazové řádce mi GNUplot funguje.

Kód: Vybrat vše

pi@raspberrypi:~ $ gnuplot

	G N U P L O T
	Version 5.2 patchlevel 6    last modified 2019-01-01 

	Copyright (C) 1986-1993, 1998, 2004, 2007-2018
	Thomas Williams, Colin Kelley and many others

	gnuplot home:     http://www.gnuplot.info
	faq, bugs, etc:   type "help FAQ"
	immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'wxt'
gnuplot> plot abs(x)
gnuplot> 
Ovšem potřebuji se do něho nějak dostat z Geany.

Stáhle jsem gnuplot-iostream
https://github.com/dstahlke/gnuplot-iostream
http://stahlke.org/dan/gnuplot-iostream/

Má tam několik examplů, ale žádný nelze zkompilovat.

Kód: Vybrat vše

// Demo of vector plot.
// Compile it with:
//   g++ -o example-vector example-vector.cc -lboost_iostreams -lboost_system -lboost_filesystem

#include <vector>
#include <cmath>
#include <boost/tuple/tuple.hpp>

#include "gnuplot-iostream.h"

int main() {
	Gnuplot gp;
	// Create a script which can be manually fed into gnuplot later:
	//    Gnuplot gp(">script.gp");
	// Create script and also feed to gnuplot:
	//    Gnuplot gp("tee plot.gp | gnuplot -persist");
	// Or choose any of those options at runtime by setting the GNUPLOT_IOSTREAM_CMD
	// environment variable.

	// Gnuplot vectors (i.e. arrows) require four columns: (x,y,dx,dy)
	std::vector<boost::tuple<double, double, double, double> > pts_A;

	// You can also use a separate container for each column, like so:
	std::vector<double> pts_B_x;
	std::vector<double> pts_B_y;
	std::vector<double> pts_B_dx;
	std::vector<double> pts_B_dy;

	// You could also use:
	//   std::vector<std::vector<double> >
	//   boost::tuple of four std::vector's
	//   std::vector of std::tuple (if you have C++11)
	//   arma::mat (with the Armadillo library)
	//   blitz::Array<blitz::TinyVector<double, 4>, 1> (with the Blitz++ library)
	// ... or anything of that sort

	for(double alpha=0; alpha<1; alpha+=1.0/24.0) {
		double theta = alpha*2.0*3.14159;
		pts_A.push_back(boost::make_tuple(
			 cos(theta),
			 sin(theta),
			-cos(theta)*0.1,
			-sin(theta)*0.1
		));

		pts_B_x .push_back( cos(theta)*0.8);
		pts_B_y .push_back( sin(theta)*0.8);
		pts_B_dx.push_back( sin(theta)*0.1);
		pts_B_dy.push_back(-cos(theta)*0.1);
	}

	// Don't forget to put "\n" at the end of each line!
	gp << "set xrange [-2:2]\nset yrange [-2:2]\n";
	// '-' means read from stdin.  The send1d() function sends data to gnuplot's stdin.
	gp << "plot '-' with vectors title 'pts_A', '-' with vectors title 'pts_B'\n";
	gp.send1d(pts_A);
	gp.send1d(boost::make_tuple(pts_B_x, pts_B_y, pts_B_dx, pts_B_dy));

#ifdef _WIN32
	// For Windows, prompt for a keystroke before the Gnuplot object goes out of scope so that
	// the gnuplot window doesn't get closed.
	std::cout << "Press enter to exit." << std::endl;
	std::cin.get();
#endif
}

Kód: Vybrat vše

g++  -std=c++17  -Wall -o "example-vector" "example-vector.cc" -l wiringPi   (in directory: /home/pi/gnuplot-iostream)
In file included from /usr/include/c++/8/vector:69,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/vector.tcc: In member function ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {boost::tuples::tuple<double, double, double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>}; _Tp = boost::tuples::tuple<double, double, double, double>; _Alloc = std::allocator<boost::tuples::tuple<double, double, double, double> >]’:
/usr/include/c++/8/bits/vector.tcc:109:4: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<boost::tuples::tuple<double, double, double, double>*, std::vector<boost::tuples::tuple<double, double, double, double> > >’ changed in GCC 7.1
    _M_realloc_insert(end(), std::forward<_Args>(__args)...);
    ^~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/vector.tcc: In member function ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {double}; _Tp = double; _Alloc = std::allocator<double>]’:
/usr/include/c++/8/bits/vector.tcc:109:4: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<double*, std::vector<double> >’ changed in GCC 7.1
    _M_realloc_insert(end(), std::forward<_Args>(__args)...);
    ^~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {boost::tuples::tuple<double, double, double, double, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>}; _Tp = boost::tuples::tuple<double, double, double, double>; _Alloc = std::allocator<boost::tuples::tuple<double, double, double, double> >]’:
/usr/include/c++/8/bits/vector.tcc:413:7: note: parameter passing for argument of type ‘std::vector<boost::tuples::tuple<double, double, double, double> >::iterator’ {aka ‘__gnu_cxx::__normal_iterator<boost::tuples::tuple<double, double, double, double>*, std::vector<boost::tuples::tuple<double, double, double, double> > >’} changed in GCC 7.1
       vector<_Tp, _Alloc>::
       ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {double}; _Tp = double; _Alloc = std::allocator<double>]’:
/usr/include/c++/8/bits/vector.tcc:413:7: note: parameter passing for argument of type ‘std::vector<double>::iterator’ {aka ‘__gnu_cxx::__normal_iterator<double*, std::vector<double> >’} changed in GCC 7.1
In file included from /usr/include/c++/8/vector:63,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = boost::tuples::tuple<double, double, double, double>*; _ForwardIterator = boost::tuples::tuple<double, double, double, double>*; _Allocator = std::allocator<boost::tuples::tuple<double, double, double, double> >]’:
/usr/include/c++/8/bits/stl_uninitialized.h:311:2: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
       return std::__uninitialized_copy_a
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = double*; _ForwardIterator = double*; _Allocator = std::allocator<double>]’:
/usr/include/c++/8/bits/stl_uninitialized.h:311:2: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
       return std::__uninitialized_copy_a
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/8/vector:64,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_vector.h: In copy constructor ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = double; _Alloc = std::allocator<double>]’:
/usr/include/c++/8/bits/stl_vector.h:463:31: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
    std::__uninitialized_copy_a(__x.begin(), __x.end(),
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
           this->_M_impl._M_start,
           ~~~~~~~~~~~~~~~~~~~~~~~
           _M_get_Tp_allocator());
           ~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/8/vector:63,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<boost::tuples::tuple<double, double, double, double>*>; _ForwardIterator = boost::tuples::tuple<double, double, double, double>*; _Tp = boost::tuples::tuple<double, double, double, double>]’:
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
     __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:289:37: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
     { return std::uninitialized_copy(__first, __last, __result); }
              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::move_iterator<double*>; _ForwardIterator = double*; _Tp = double]’:
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
     __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:289:37: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
     { return std::uninitialized_copy(__first, __last, __result); }
              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _ForwardIterator = double*; _Tp = double]’:
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:287:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:289:37: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     { return std::uninitialized_copy(__first, __last, __result); }
              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<boost::tuples::tuple<double, double, double, double>*>; _ForwardIterator = boost::tuples::tuple<double, double, double, double>*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
     uninitialized_copy(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:134:15: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
       return std::__uninitialized_copy<__is_trivial(_ValueType1)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __is_trivial(_ValueType2)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __assignable>::
            ~~~~~~~~~~~~~~~~~~
  __uninit_copy(__first, __last, __result);
  ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<double*>; _ForwardIterator = double*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
     uninitialized_copy(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:134:15: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
       return std::__uninitialized_copy<__is_trivial(_ValueType1)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __is_trivial(_ValueType2)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __assignable>::
            ~~~~~~~~~~~~~~~~~~
  __uninit_copy(__first, __last, __result);
  ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _ForwardIterator = double*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     uninitialized_copy(_InputIterator __first, _InputIterator __last,
     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:115:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:134:15: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
       return std::__uninitialized_copy<__is_trivial(_ValueType1)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __is_trivial(_ValueType2)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            && __assignable>::
            ~~~~~~~~~~~~~~~~~~
  __uninit_copy(__first, __last, __result);
  ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In static member function ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<boost::tuples::tuple<double, double, double, double>*>; _ForwardIterator = boost::tuples::tuple<double, double, double, double>*; bool _TrivialValueTypes = false]’:
/usr/include/c++/8/bits/stl_uninitialized.h:76:9: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
         __uninit_copy(_InputIterator __first, _InputIterator __last,
         ^~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:76:9: note: parameter passing for argument of type ‘std::move_iterator<boost::tuples::tuple<double, double, double, double>*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h: In static member function ‘static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator<double*>; _ForwardIterator = double*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:99:9: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
         __uninit_copy(_InputIterator __first, _InputIterator __last,
         ^~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:99:9: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:101:27: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
         { return std::copy(__first, __last, __result); }
                  ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h: In static member function ‘static _ForwardIterator std::__uninitialized_copy<true>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _ForwardIterator = double*]’:
/usr/include/c++/8/bits/stl_uninitialized.h:99:9: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
         __uninit_copy(_InputIterator __first, _InputIterator __last,
         ^~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_uninitialized.h:99:9: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_uninitialized.h:101:27: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
         { return std::copy(__first, __last, __result); }
                  ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/8/vector:60,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_algobase.h: In function ‘_OI std::copy(_II, _II, _OI) [with _II = std::move_iterator<double*>; _OI = double*]’:
/usr/include/c++/8/bits/stl_algobase.h:446:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
     copy(_II __first, _II __last, _OI __result)
     ^~~~
/usr/include/c++/8/bits/stl_algobase.h:446:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_algobase.h: In function ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _OI = double*]’:
/usr/include/c++/8/bits/stl_algobase.h:446:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_algobase.h:446:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
/usr/include/c++/8/bits/stl_algobase.h:455:8: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
       return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        (std::__miter_base(__first), std::__miter_base(__last),
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         __result));
         ~~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/vector:60,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_iterator.h: In function ‘decltype (std::__miter_base(__it.base())) std::__miter_base(std::move_iterator<_IteratorL>) [with _Iterator = double*]’:
/usr/include/c++/8/bits/stl_iterator.h:1238:5: note: parameter passing for argument of type ‘std::move_iterator<double*>’ changed in GCC 7.1
     __miter_base(move_iterator<_Iterator> __it)
     ^~~~~~~~~~~~
In file included from /usr/include/c++/8/bits/stl_algobase.h:61,
                 from /usr/include/c++/8/vector:60,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/cpp_type_traits.h: In function ‘_Iterator std::__miter_base(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >]’:
/usr/include/c++/8/bits/cpp_type_traits.h:419:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     __miter_base(_Iterator __it)
     ^~~~~~~~~~~~
In file included from /usr/include/c++/8/vector:60,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_algobase.h: In function ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<const double*, std::vector<double> >; _OI = double*]’:
/usr/include/c++/8/bits/stl_algobase.h:420:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     __copy_move_a2(_II __first, _II __last, _OI __result)
     ^~~~~~~~~~~~~~
/usr/include/c++/8/bits/stl_algobase.h:420:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
In file included from /usr/include/c++/8/bits/stl_algobase.h:67,
                 from /usr/include/c++/8/vector:60,
                 from example-vector.cc:5:
/usr/include/c++/8/bits/stl_iterator.h: In function ‘_Iterator std::__niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container>) [with _Iterator = const double*; _Container = std::vector<double>]’:
/usr/include/c++/8/bits/stl_iterator.h:987:5: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<const double*, std::vector<double> >’ changed in GCC 7.1
     __niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
     ^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `boost::iostreams::stream<boost::iostreams::file_descriptor_sink, std::char_traits<char>, std::allocator<char> >::stream<int, boost::iostreams::file_descriptor_flags>(int const&, boost::iostreams::file_descriptor_flags const&, boost::disable_if<boost::is_same<int, boost::iostreams::file_descriptor_sink>, void>::type*)':
example-vector.cc:(.text._ZN5boost9iostreams6streamINS0_20file_descriptor_sinkESt11char_traitsIcESaIcEEC2IiNS0_21file_descriptor_flagsEEERKT_RKT0_PNS_10disable_ifINS_7is_sameIS9_S2_EEvE4typeE[_ZN5boost9iostreams6streamINS0_20file_descriptor_sinkESt11char_traitsIcESaIcEEC2IiNS0_21file_descriptor_flagsEEERKT_RKT0_PNS_10disable_ifINS_7is_sameIS9_S2_EEvE4typeE]+0x84): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `boost::iostreams::file_descriptor_sink boost::iostreams::detail::wrap<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink const&, boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::file_descriptor_sink>, void>::type*)':
example-vector.cc:(.text._ZN5boost9iostreams6detail4wrapINS0_20file_descriptor_sinkEEET_RKS4_PNS_10disable_ifINS0_9is_std_ioIS4_EEvE4typeE[_ZN5boost9iostreams6detail4wrapINS0_20file_descriptor_sinkEEET_RKS4_PNS_10disable_ifINS0_9is_std_ioIS4_EEvE4typeE]+0x20): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `boost::iostreams::detail::concept_adapter<boost::iostreams::file_descriptor_sink>::concept_adapter(boost::iostreams::file_descriptor_sink const&)':
example-vector.cc:(.text._ZN5boost9iostreams6detail15concept_adapterINS0_20file_descriptor_sinkEEC2ERKS3_[_ZN5boost9iostreams6detail15concept_adapterINS0_20file_descriptor_sinkEEC5ERKS3_]+0x20): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `boost::iostreams::detail::concept_adapter<boost::iostreams::file_descriptor_sink>::concept_adapter(boost::iostreams::detail::concept_adapter<boost::iostreams::file_descriptor_sink> const&)':
example-vector.cc:(.text._ZN5boost9iostreams6detail15concept_adapterINS0_20file_descriptor_sinkEEC2ERKS4_[_ZN5boost9iostreams6detail15concept_adapterINS0_20file_descriptor_sinkEEC5ERKS4_]+0x24): undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `int boost::iostreams::detail::write_device_impl<boost::iostreams::output>::write<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, boost::iostreams::char_type_of<boost::iostreams::file_descriptor_sink>::type const*, int)':
example-vector.cc:(.text._ZN5boost9iostreams6detail17write_device_implINS0_6outputEE5writeINS0_20file_descriptor_sinkEEEiRT_PKNS0_12char_type_ofIS7_E4typeEi[_ZN5boost9iostreams6detail17write_device_implINS0_6outputEE5writeINS0_20file_descriptor_sinkEEEiRT_PKNS0_12char_type_ofIS7_E4typeEi]+0x28): undefined reference to `boost::iostreams::file_descriptor::write(char const*, int)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `std::fpos<__mbstate_t> boost::iostreams::detail::seek_device_impl<boost::iostreams::any_tag>::seek<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, long long, std::_Ios_Seekdir, std::_Ios_Openmode)':
example-vector.cc:(.text._ZN5boost9iostreams6detail16seek_device_implINS0_7any_tagEE4seekINS0_20file_descriptor_sinkEEESt4fposI11__mbstate_tERT_xSt12_Ios_SeekdirSt13_Ios_Openmode[_ZN5boost9iostreams6detail16seek_device_implINS0_7any_tagEE4seekINS0_20file_descriptor_sinkEEESt4fposI11__mbstate_tERT_xSt12_Ios_SeekdirSt13_Ios_Openmode]+0x2c): undefined reference to `boost::iostreams::file_descriptor::seek(long long, std::_Ios_Seekdir)'
/usr/bin/ld: /tmp/ccyHMVRa.o: in function `void boost::iostreams::detail::close_impl<boost::iostreams::closable_tag>::close<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, std::_Ios_Openmode)':
example-vector.cc:(.text._ZN5boost9iostreams6detail10close_implINS0_12closable_tagEE5closeINS0_20file_descriptor_sinkEEEvRT_St13_Ios_Openmode[_ZN5boost9iostreams6detail10close_implINS0_12closable_tagEE5closeINS0_20file_descriptor_sinkEEEvRT_St13_Ios_Openmode]+0x30): undefined reference to `boost::iostreams::file_descriptor::close()'
collect2: error: ld returned 1 exit status
Compilation failed.
Neporadil by prosím někdo? Na netu je milión návodů, jak"gnuplot-iostream.h" používat, ale nikde co dělat, když to nejde zkompilovat.
LinuxCNC - MESA 7i96
zz912.webnode.cz
prcek
Příspěvky: 692
Registrován: 31. 10. 2016, 2:26

5. 9. 2020, 2:24

uz je cas, kdy mi to moc nemysli, ale nechybi ti nejake knihovny a parametry, ze to s nima chces slinkovat...
v examplu je

g++ -o example-vector example-vector.cc -lboost_iostreams -lboost_system -lboost_filesystem

a ve tvem vystupu mi nektera ta -lxxxx chybi ....
--
Všechno je snadné, než to zkusíš sám.
Uživatelský avatar
zz912
Příspěvky: 1348
Registrován: 25. 5. 2008, 7:16

5. 9. 2020, 7:11

Zkoušel jsem různé varianty kompilace. Tohle je jen jedna z mnoha variant. Zkoušel jsem to i bez knihoven lxxxx. Respektive s tím jsem začínal a pak jsem našel někde nějaký návod tohle zkusit s knihovnami lxxxx. Nevím zda je to tím Raspberry, že nemůžu nic najít. Dnes už vím, že tam musí být -std=c++17 , protože je to napsané pro nejnovější verzi c-čka.

Zkoušel jsem i tuhle knihovnu:
https://github.com/alandefreitas/matplotplusplus
a taky se nepovedlo zkompilovat.

U Arduina jsem si zvykl na to, že většina programů z netu nelze zkompilovat, protože se stále aktualizují knihovny. Ovšem to mě nikdy netrápilo, protože jsem si většinu napsal sám, abych to měl pod kontrolu. Používal jsem knihovny akorát, na displeje a tam jsem měl kliku, že ty zrovna fungovali, nebo jsem si je vydupal od dodavatelů, kteří je prodávali jako Plug and play.

Nemá v sobě g++ něco integrovaného, na čem by šlo zobrazovat alespoň body, tak jak má integrovanou konzoli, která jede na všem? To zobrazování potřebuji jen pro sebe, abych si zkontrolovat části programu, zda fungují, tak jak předpokládám.
LinuxCNC - MESA 7i96
zz912.webnode.cz
Mex
Příspěvky: 10288
Registrován: 6. 2. 2014, 10:29

6. 9. 2020, 1:44

Moc tomu nerozumím.
Je možné, že nechápu, čeho se vlastně snažíš dosáhnou.
Ale je možné i to, že Ty nevíš, čeho se snažíš dosáhnout.

Jednotlivé komponenty:
g++ je překladač. Jen a pouze překladač. Jeho úkolem je ze souboru v jazyce C nebo C++ vyrobit spustitelný program pro danou platformu.
Takže samozřejmě nic pro malování nemá. Umí jen překládat. Ale zato to umí dobře a navíc je zadarmo.

Geany je textový editor, který má nějaké základní funkce IDE. Navíc se dá pomocí pluginů rozčiřit o další funkce.
Tedy primárně je dělaný je k tomu, abys v něm psal svůj program. Ty IDE funkce pak umožňují, abys přímo z něho spustil překlad (tedy to g++), případně s nějakým pluginem případně i debug.
Takže mi uníká, co jsi myslel pod pojmem "dostat se do GNU plotu z Geany".
Všechno, co Geany udělá (spuštění překladu, ladění atd.) musíš být schopný spustit i ručně bez něho. Takže napřed si to rozchoď v ručním režimu, nějakou "automatizaci" přes Geany můžeš udělat až to bude chodit.

GNUplot je program, který umí na základě předaných dat namalovat nějaký graf. Standardně čeká ta data interaktivně od uživatele, ale dá se to tam poslat i jinak.

Nějaké ty knihovny pro připojení ke GNUplot fungují zřejmě tak, že vytvoří interface mezi nějakým programem a programem GNUplot. Takže ten program to nasype do nějakého pole (nebo moderněji, a podle mě blběji, do nějakého "vektoru"), ten se pak natlačí do GNUplot a ten to namaluje.

No a teď do toho ještě vstupuje to, že to chceš programovat na/pro RPi. Jde o to, jestli je to NA nebo PRO. Tedy jestli to celé chceš dělat přímo na tom RPi, nebo to budeš dělat na PC ale generovat pro spuštění na RPi.
Od toho se odvíjí co musí být nakonfigurováno pro jakou platformu.
Tedy například jestli g++ má být určeno pro RPi a generovat kód pro RPi, nebo má být určeno pro PC a generovat kód pro RPi.
Stejně tak je otázka, kde poběží třeba ten GNUplot, a nakonec i to Geany.

Ale jak říkám, třeba to celé blbě chápu.
Zkus trochu víc popsat koncepčně o co Ti jde, co chceš zobrazovat za data, jak vzniknou, kde je chceš zobrazovat a jak je chceš zobrazovat.
Uživatelský avatar
zz912
Příspěvky: 1348
Registrován: 25. 5. 2008, 7:16

6. 9. 2020, 6:58

Mex píše: 6. 9. 2020, 1:44 g++ je překladač. Jen a pouze překladač. Jeho úkolem je ze souboru v jazyce C nebo C++ vyrobit spustitelný program pro danou platformu.
Takže samozřejmě nic pro malování nemá. Umí jen překládat. Ale zato to umí dobře a navíc je zadarmo.
No a jak je to například s klasickou konzolí:

Kód: Vybrat vše

// Your First C++ Program

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
?

<iostream> je také nějaká knihovna? Je součástí g++, Geany, nebo operačního systému?
Já jsem ve svých úvahách předpokládal, že je součástí g++, proto jsem hledal něco podobného, ale pro zobrazování grafiky (v mém případě alespoň bodů, ideálně úseček)
Jakmile vidím že je v #include <ixxxx.h> písmeno h, tak vím že budou problémy, jakmile tam h není například <iostream>, tak to lze většinou bez problémů zkompilovat.
Mex píše: 6. 9. 2020, 1:44 Takže mi uníká, co jsi myslel pod pojmem "dostat se do GNU plotu z Geany".
Tím jsem myslel postup:
- zapnu RPi
- spustím program Geany v "režimu" c++
- "NĚCO" (zdrojový kód) napíšu v Geany, popřípadě "NĚCO" v Geany nastavím
- zobrazí se mi graf, třeba přes GNUplot
- následně si to přizpůsobím pro svůj program

Mex píše: 6. 9. 2020, 1:44 No a teď do toho ještě vstupuje to, že to chceš programovat na/pro RPi. Jde o to, jestli je to NA nebo PRO. Tedy jestli to celé chceš dělat přímo na tom RPi, nebo to budeš dělat na PC ale generovat pro spuštění na RPi.
Od toho se odvíjí co musí být nakonfigurováno pro jakou platformu.
Tedy například jestli g++ má být určeno pro RPi a generovat kód pro RPi, nebo má být určeno pro PC a generovat kód pro RPi.
Stejně tak je otázka, kde poběží třeba ten GNUplot, a nakonec i to Geany.
"Od toho se odvíjí co musí být nakonfigurováno pro jakou platformu."
No tady bude asi zakopaný pes, že nevím co se pro jakou platformu nastavuje.
Abych si nekomplikoval život, vše bude na RPi. Jak Geany, tak g++, tak zobrazování grafu.
Jak Geany, tak g++ je již součástí distribuce.
Mex píše: 6. 9. 2020, 1:44 Zkus trochu víc popsat koncepčně o co Ti jde, co chceš zobrazovat za data, jak vzniknou, kde je chceš zobrazovat a jak je chceš zobrazovat.
Bohužel nejsem zkušený programátor, který napíše 100 řádkový program a pak si jej jen pro kontrolu spustí. Vždy když napíšu pár řádků, tak pak musím dát zkompilovat a spustit svůj program, abych věděl, že jdu tím správným směrem.

V arduinu jsem používal Serial Monitor a Serial Plotter.
plotter.png
Serial Monitor jsem si nahradil konzolí "std::cout << "Hello World!";" , ale nemohu najít náhradu za Serial Plotter.
Defakto potřebuji jen "něco" abych vykreslil 2D úsečky. Ať už to bude jakýkoliv postup, já se přizpůsobím.
Teoreticky bych mohl vygenerovat sloupeček souřadnic x1,y1,x2,y2 ten vzít COPY PASTE do Excelu a tam udělat graf. Ovšem to bych ten program ladil asi 1000 let.

Myslím si, že mám dostatečné logické myšlení, abych zvládl naprogramovat, to co bych chtěl, ale vždy se zaseknu na nějaké kravině(například že neumím vykreslit body). Klidně i přemýšlím, že bych vše zahodil a zkusil něco komerčního s podporou, ale PLC-čka jsou na to co potřebuji pomalá a psát tento program v ladderu by bylo na zabití. Nic jiného než RPi+gpio mě nenapadá, nebo neznám. Defakto vše začalo tak, že mi nestačil výkon Arduina MEGA + velikost SRAM a šáhl jsem po RPi.
LinuxCNC - MESA 7i96
zz912.webnode.cz
Mex
Příspěvky: 10288
Registrován: 6. 2. 2014, 10:29

6. 9. 2020, 8:23

Jen krátce, mám trochu problémy s psaním (jsem na cestách).

iostream je základní vstup/výstupní knihovna pro C++. Takže pokud použiješ nějakou konstrukci, která něco z ní využívá, tak Ti překladač g++ automaticky tuto knihovnu přilinkuje k Tvému programu.

K tématu vývoje "na" nebo "pro" RPi:
Uvědomuješ si doufám, že tady chceš použít jiný model než jsi používal s Arduinem. Při použití Arduina to Arduino spočítalo nějaká data, poslalo je na PC po sériové lince, a nějaké omalovánky už řešilo PC.
Ale s RPi to chceš (podle svých slov) dělat jinak - tady bude omalovánky řešit to RPi. Což je dost značná změna.

Jestli dělat vše na cílové platformě (jak to zvažuješ teď) nebo to dělat jako cross-vývoj (jako jsi to dělal dosud s Arduinem) je vždy na zvážení. Obě varianty mají své plusy i své mínusy:

vše na cílové plaformě:
+ jednodušší konfigurace vývojového prostředí
- pomalejší stroj, překlad a další operace většinou trvají mnohem déle
- méně zdrojů, některé aplikace může být problém vůbec spustit, nebo jich sputit víc najednou
- některé aplikace pro dané prostředí vůbec nemusí být k dispozici, resp. je třeba je pro dané prostředí zkompilovat

cross konfigurace:
+ výkonnější a rychlejší vývoj
+ připadný problém vytuhnutím laděného objektu při nějaké chybě neohrozí vývojové pracoviště
+ cílová platforma může být i velmi slabá a omezená
- většinou o dost slořitější konfigurace vývojových nástrojů, pokud to není nějaké "předvařené" řešení ala Arduino

Já osobně pokud můžu a umím, tak se snažim spíš dělat vývoj distribuovaně (cross varianta). Podobně jako Ty rád ladím po malých částech a snažím se mít vývojové prostředí udělané tak, aby celý cyklus změna-překlad-pokus byla co nejrychlejší. Včetně toho, abych mohl kdykoli zresetovat cílový stroj bez toho, abych přišel o změny ve zdrojáku.
No ale vždy to tak nejde. Teď jsem si třeba hrál s laděním EtherCATu na desce OrangePi. A tam by to nakonfigurování cross pracoviště bylo příliš pracné, tak jsem to překládal a ladil přímo na něm. Nicméně si teď po praktické zkušenosti myslím, že jsem asi přece jen měl investovat ten čas do konfigurace cross modelu vývoje. A do budoucna to asi udělám.

Jedno doporučení na závěr (opsal jsem ho od Komenského): postupuj od jednoduchého ke složitému. Obecně jakákoli práce s grafikou je většinou výrazně složitější než nějaké jednoduché vypsání textu. Tak napřed dostaň do ruky tu textovou cestu a teprve pak se pouštěj do grafiky.
Uživatelský avatar
zz912
Příspěvky: 1348
Registrován: 25. 5. 2008, 7:16

7. 9. 2020, 12:31

Děkuji všem za rady a pomoc. Nakonec jsem vyzkoušel vypreparovat z examplů ten nejjednodušší způsob jak z C++ se dostat do Gnuplot.

Kód: Vybrat vše

#include "gnuplot-iostream.h"

int main() {

 Gnuplot gp;
 
 gp << "plot sin(x) \n" << std::endl;

  return 0;
}
a výsledek:

Kód: Vybrat vše

g++ -std=c++17 -Wall -o "zz912-001" "zz912-001.cc"  -lboost_iostreams -lboost_system -lboost_filesystem (in directory: /home/pi/gnuplot-iostream)
Compilation finished successfully.
Gnuplot.PNG
Teď se jen naučit používat Gnuplot a nahradit "plot sin(x)" tím, co potřebuji.
LinuxCNC - MESA 7i96
zz912.webnode.cz
prcek
Příspěvky: 692
Registrován: 31. 10. 2016, 2:26

7. 9. 2020, 1:57

Preji ti hodne stesti, protoze gnuplot je nastroj velmi mocny, ale rozhodne ne jednoduchy. (nakonec jsem v nem vzdy vykreslil, co jsem chtel, ale rozhodne s nim neumim)

Stejne furt nechapu oc se snazis, ale to nevadi, hlavne, ze ti to funguje.
--
Všechno je snadné, než to zkusíš sám.
Odpovědět

Zpět na „Ostatní software“