Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3854

C/C++ • Re: Boost provides free peer-reviewed portable C++ source libraries.

$
0
0
Boost libraries are mostly header only libraries.
At several places in boost documentation it is stated to compile with optimization (because of that).
What I typically do is to compile with "-Wall -pedantic -Wextra" as well.

I was surprised to see compiler warning not in my code but in a used by my code BGL header file:

Code:

pi@raspberrypi5:~ $ f=straight_line_graphvizpi@raspberrypi5:~ $ g++ -O3 -Wall -pedantic -Wextra $f.cpp -o $fIn file included from /usr/include/c++/12/string:47,...In file included from straight_line_graphviz.cpp:29:/usr/include/boost/graph/chrobak_payne_drawing.hpp: In function ‘int main(int, char**)’:/usr/include/boost/graph/chrobak_payne_drawing.hpp:207:22: note: ‘next_to_rightmost’ was declared here  207 |             vertex_t next_to_rightmost;      |                      ^~~~~~~~~~~~~~~~~pi@raspberrypi5:~ $ 

That warning does not happen on my updated+upgraded to latest x86_64 Ubuntu 22.04.
This although that header file is identical on both systems.

The difference is the compiler version:

Code:

hermann@7950x:~$ g++ --version | head -1g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0hermann@7950x:~$ 

Code:

pi@raspberrypi5:~ $ g++ --version | head -1g++ (Debian 12.2.0-14) 12.2.0pi@raspberrypi5:~ $ 
I fixed the header file on my Pi5 with …

Code:

sudo vi /usr/include/boost/graph/chrobak_payne_drawing.hpp
… and this small change:

Code:

...            left[v] = right[leftmost];//            vertex_t next_to_rightmost;            vertex_t next_to_rightmost = graph_traits< Graph >::null_vertex();            for (vertex_t temp = leftmost; temp != rightmost;...
Now the compiler warning is resolved, as well as cpplint and cppcheck are fine according header specification:
https://gist.github.com/Hermann-SW/99d1 ... -cpp-L6-L9

Code:

pi@raspberrypi5:~ $ f=straight_line_graphvizpi@raspberrypi5:~ $ g++ -O3 -Wall -pedantic -Wextra $f.cpp -o $fpi@raspberrypi5:~ $ cpplint --filter=-legal/copyright,-build/namespaces $f.cppDone processing straight_line_graphviz.cpppi@raspberrypi5:~ $ cppcheck --enable=all --suppress=missingIncludeSystem $f.cpp --check-configChecking straight_line_graphviz.cpp ...pi@raspberrypi5:~ $ 


BGL and my gist can be used headless despite graphics in browser.
This was needed to make my Ubuntu capable:

Code:

pi@raspberrypi5:~ $ ssh -X hermann@7950xhermann@7950x's password: Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 6.5.0-25-generic x86_64)...hermann@7950x:~$ tail -1 .bashrc export XAUTHORITY=$HOME/.Xauthorityhermann@7950x:~$ 

Now

Code:

hermann@7950x:~$ GraphvizFiddle.py chromium-browser <(./straight_line_graphviz <(randomgraph 80 -o -))-------------------------------------malloc: 18   malloc-free: 0
does use chromium-browser on Pi5 despite being started headless on my 7950x machine.

The 80 vertices random maximal planar graph is bit big in browser.
So I added manually size="10,200" at bottom and clicked on "Draw" button to get the graph displayed in less area.
Yes, the vertex labels cannot be read anymore, but the straight line drawing planar layout comes out clear:
BGL.straight_line_graphviz.4.80.png

P.S:
I forgot to mention that "chrobak_payne_straight_line_drawing()"
https://www.boost.org/doc/libs/1_74_0/l ... awing.html

creates grid integer coordinates according doc:
A straight line drawing of a planar graph is a plane drawing where each edge is drawn using a straight line segment. Since all edges are line segments, the drawing is completely determined by the placement of vertices in the plane. chrobak_payne_straight_line_drawing uses an algorithm of Chrobak and Payne [71] to form a straight line drawing of a planar graph by mapping all n vertices in a planar graph to integer coordinates in a (2n - 4) x (n - 2) grid.

Statistics: Posted by HermannSW — Sat Mar 16, 2024 1:28 am



Viewing all articles
Browse latest Browse all 3854

Trending Articles