Livre récent de Stroustrup, FLTK et Linux
Bonjour à tous.
Désirant me familiariser avec le C++ j'ai acheté le tout récent ouvrage de Stroustrup, le créateur et mainteneur du C++ :
Programming, Principles and Practise Using C++ (voir http://www.stroustrup.com/Programming/ ).
J'ai étudié à fond les onze excellents premiers chapitres. Mais arrivé au douzième, qui aborde les applications graphiques (jusqu'à ce point tout est en console), ça se gâte, les explications données dans le livre pour l'installation des outils graphiques utilisés concernant plutôt Windows... alors que je suis sous une distribution Linux.
A noter que je me sers simplement de Kate comme éditeur et de g++ comme compilateur, sans IDE.
Pour introduire la programmation graphique, il est fait usage dans le livre (chap 12 et suivants) de la librairie graphique FLTK, que j'ai installée sans problème.
A l'Appendice D, p. 1160, $D.5, on trouve ceci :
Citation:
Create a sigle new .cpp file in your newly created project and enter the following code. It should compile without problems.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| // Fichier essai.cpp
#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Window.h>
int main()
{
Fl_Window window(200,200,"Window title");
Fl_Box box(0,0,200,200,"Hello World");
window.show();
return Fl::run();
} |
Ce code se compile sans problème avec :
Code:
g++ essai.cpp -lftlk
(une fois du moins les .h des en-têtes remplacés par des .H !) puis s'exécute correctement.
Toutefois si je tente d'exécuter des programmes graphiques du livre (chapitres 12 et suivants), rien à faire.
De quelque façon que je m'y prenne j'obtiens des messages d'erreur.
Quelqu'un a-t-il réussi à faire fonctionner sous Linux la partie graphique de l'ouvrage ??
Exemple, le programme :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| //
// This is example code from Chapter 12.3 "A first example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include <FL/Fl.H> // ajouté par ptyxs
#include <FL/Fl_Box.H> // ajouté par ptyxs
#include <FL/Fl_Window.H> // ajouté par ptyxs
#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilitie
//------------------------------------------------------------------------------
int main()
{
using namespace Graph_lib; // our graphics faciqlities are in Graph_lib
Point tl(100,100); // to become top left corner of window
Simple_window win(tl,600,400,"Canvas"); // make a simple window
Polygon poly; // make a shape (a polygon)
poly.add(Point(300,200)); // add a point
poly.add(Point(350,100)); // add another point
poly.add(Point(400,200)); // add a third point
poly.set_color(Color::red); // adjust properties of poly
win.attach (poly); // connect poly to the window
win.wait_for_button(); // give control to the display engine
}
//------------------------------------------------------------------------------ |
compilé ainsi :
Code:
g++ Graph.cpp Window.cpp Simple_Window.cpp chapter.12.3.cpp -lfltk
donne une erreur de l'éditeur de liens :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| toto@tux-laptop:~/Programmes/C++/stroustrup/Chapter12$ g++ Graph.cpp Window.cpp Simple_window.cpp chapter.12.3.cpp -lfltk
/tmp/ccJSfJON.o: In function `Graph_lib::Image::Image(Point, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Graph_lib::Suffix::Encoding)':
Graph.cpp:(.text+0x148f): undefined reference to `Fl_JPEG_Image::Fl_JPEG_Image(char const*)'
Graph.cpp:(.text+0x14ee): undefined reference to `Fl_GIF_Image::Fl_GIF_Image(char const*)'
/tmp/ccJSfJON.o: In function `Graph_lib::Image::Image(Point, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Graph_lib::Suffix::Encoding)':
Graph.cpp:(.text+0x1883): undefined reference to `Fl_JPEG_Image::Fl_JPEG_Image(char const*)'
Graph.cpp:(.text+0x18e2): undefined reference to `Fl_GIF_Image::Fl_GIF_Image(char const*)'
/tmp/ccjDzjsE.o: In function `Graph_lib::Button::~Button()':
Simple_window.cpp:(.text._ZN9Graph_lib6ButtonD1Ev[Graph_lib::Button::~Button()]+0xb): undefined reference to `vtable for Graph_lib::Button'
/tmp/ccjDzjsE.o: In function `Graph_lib::Button::Button(Point, int, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(void*, void*))':
Simple_window.cpp:(.text._ZN9Graph_lib6ButtonC1E5PointiiRKSsPFvPvS4_E[Graph_lib::Button::Button(Point, int, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, void (*)(void*, void*))]+0x40): undefined reference to `vtable for Graph_lib::Button'
collect2: ld a retourné 1 code d'état d'exécution |
Comment diable compiler correctement les programmes proposés par Stroustrup dans le chapitre 12 et suivants ?