Компиляция программ с графическим пользовательским интерфейсом (GUI) FLTK или Fox-Toolkit

Компиляция программ с графическим пользовательским интерфейсом (GUI) FLTK или Fox-Toolkit

Программа из примеров для FLTK в директории 'test' под названием 'hello.cxx':

// "$Id: hello.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $"
// Hello, World! program for the Fast Light Tool Kit (FLTK).
// Copyright 1998-2010 by Bill Spitzak and others.
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//     http://www.fltk.org/COPYING.php
// Please report all bugs and problems on the following page:
//     http://www.fltk.org/str.php

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv)
// создание окна fltk указанным размером в пикселях
Fl_Window *window = new Fl_Window(340,180);

// создаем коробку с координатами 20,40, размером 300,100 и текстом 'Hello, World!'
Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");

// настраиваем тип границы коробки

// устанавливаем шрифт, размер текста и тип вывода текста

// заканчиваем формирование интерфейса окна

// запускаем цикл событий fltk
window->show(argc, argv);

return Fl::run();

// End of "$Id: hello.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $".

Компилируйте код программы с правильными параметрами для того, чтобы не получить следующую ошибку:

hello.cxx:(.text+0x35): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)'


$ g++ -lfltk hello.cxx -o hello

Программа из примеров для Fox Toolkit в директории 'tests' под названием 'hello.cpp':

#include <fox-1.6/fx.h>


  This is a classical programming example.  Doing it graphically
  using FOX is, as you see, not a whole lot more involved than
  its command-line equivalent!

  Note the following things:

    - Each FOX application needs one (and only one) application
      object (FXApp).

    - Before doing anything, the application object needs to be
      initialized.  You need to pass argc and argv so that certain
      command line arguments may be filtered out by FOX (e.g. -display).

    - You need to create at least one toplevel window; in this case,
      that is FXMainWindow.

    - FOX widgets are nested simply by creating them in the right order.
      Here, we create FXButton as a child of "main."

    - A single call to FXApp::create() will create X windows for each
      widget.  Until calling create(), a widget exists only at the client,
      and has no associated X window yet.

    - Finally, FXApp::run() will start the main event loop.  This will
      only return when the application is done.


#include <fox-1.6/FXExpression.h>

// The entry point where the program starts running
int main(int argc,char **argv){

  // Each FOX GUI program needs one, and only one, application object.
  // The application objects coordinates some common stuff shared between
  // all the widgets; for example, it dispatches events, keeps track of
  // all the windows, and so on.
  // We pass the "name" of the application, and its "vendor", the name
  // and vendor are used to search the registry database (which stores
  // persistent information e.g. fonts and colors).
  FXApp application("Hello","FoxTest");

  // Here we initialize the application.  We pass the command line arguments
  // because FOX may sometimes need to filter out some of the arguments.
  // This opens up the display as well, and reads the registry database
  // so that persistent settings are now available.

  // This creates the main window. We pass in the title to be displayed
  // above the window, and possibly some icons for when its iconified.
  // The decorations determine stuff like the borders, close buttons,
  // drag handles, and so on the Window Manager is supposed to give this
  // window.
  FXMainWindow *main=new FXMainWindow(&application,"Hello",NULL,NULL,DECOR_ALL);

  // Here we create a button.  The button has a label on it, but no icon in
  // this case.  An '&' followed by a letter introduces a hot-key so you can
  // invoke this button from the keyboard.
  // The button sends an ID_QUIT message to the application object, which
  // in its default implementation causes the program to quit.
  new FXButton(main,"&Hello, World!",NULL,&application,FXApp::ID_QUIT);

  // This "realizes" the widget tree.  This is necessary because GUI's are
  // a client-server system, i.e. there are actually two programs involved,
  // a client (in this case, "hello world"), and a server (The X11 server or
  // Windows GDI).  We can build our C++ widgets but something extra is needed
  // to tell the server that we want windows on the screen.  Besides windows,
  // there are various other resources that need to be created, such as icons,
  // fonts, and so on.  This call recurses through the entire widget tree and
  // creates them all, insofar as it can know about them.

  // Pretty self-explanatory:- this shows the window, and places it in the
  // middle of the screen.

  // Now, we actually run the application.  This does not return until we
  // quit. The function run() is a simple loop which gets events from the
  // user, executes them, and then waits for the next event, and so on until
  // we hit the button.
  return application.run();

Компилируйте код программы с правильными параметрами для того, чтобы не получить следующую ошибку:

hello.cpp:(.text+0x21): undefined reference to `FX::FXString::FXString(char const*)'


$ g++ -I/usr/local/include/fox-1.6 -lFOX-1.6 hello.cpp -o hello


$ g++ `pkg-config --libs --cflags fox` hello.cpp -o hello

Тэги: fltk, fox_toolkit, toolkit, freebsd, bsd, programado, c_plus_plus

Комментариев нет:

Отправить комментарий