FLTK_WRAP_UI error in Ubuntu 14

32 views
Skip to first unread message

Ibrahim A

unread,
Aug 16, 2016, 12:55:14 PM8/16/16
to fltk.general
Dear All,
I am trying to build another simple fltk example using cmake. I have two files foo.cxx and ui.fl in addition to the CMakeLists.txt. I tried to use FLTK_WRAP_UI but I get this error when I run make command:
------------------------------------------------------
Scanning dependencies of target ui
[ 25%] Building CXX object CMakeFiles/ui.dir/foo.cxx.o
/home/ibr/ZmyProjects/fltk/gui_ex01/src/foo.cxx:1:16: fatal error: ui.h: No such file or directory
 #include "ui.h"
                ^
compilation terminated.
make[2]: *** [CMakeFiles/ui.dir/foo.cxx.o] Error 1
make[1]: *** [CMakeFiles/ui.dir/all] Error 2
make: *** [all] Error 2
------------------------------------------------------
I noticed that the files ui.h and ui.cxx are not generated. When using cmake-gui, some fltk variables are missing e.g fluid executable. Any suggestion? 
Here are the files contents:
------------------------------------------------------
foo.cxx
------------------------------------------------------
#include "ui.h"
int main(  ){
    ui gui;
    gui.Show();
    Fl::run();
    
    return 0;
}
------------------------------------------------------
ui.fl
------------------------------------------------------
# data file for the Fltk User Interface Designer (fluid)
version 1.0303 
header_name {.h} 
code_name {.cxx}
class foo {open
} {
  Function {foo()} {open
  } {
    Fl_Window controlPanel {open
      xywh {65 52 590 440} type Single visible
    } {
      Fl_Button {} {
        label Quit
        xywh {225 250 120 40}
      }
      Fl_Box {} {
        label {FLTK + ITK}
        xywh {135 105 305 100} labelfont 9 labelsize 20
      }
    }
  }
  Function {~foo()} {open
  } {}
  Function {Quit()} {open
  } {
    code {this->Hide();} {}
  }
  Function {Hide()} {open
  } {
    code {controlPanel->hide();} {}
  }
  Function {Show()} {open
  } {
    code {controlPanel->show();} {}
  }
------------------------------------------------------
 CMakeLists.txt
------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.1)
PROJECT(foo)

FIND_PACKAGE(FLTK REQUIRED NO_MODULE)  
include_directories(${FLTK_INCLUDE_DIRS}) 
link_directories(${FLTK_LIBRARY_DIRS}) 
add_definitions(${FLTK_DEFINITIONS}) 

ADD_EXECUTABLE( foo foo.cxx ) 
FLTK_WRAP_UI( foo ui.fl )

ADD_LIBRARY(ui foo.cxx ${ui_FLTK_UI_SRCS})
ADD_DEPENDENCIES(foo ui)

TARGET_LINK_LIBRARIES( foo fltk ) 
------------------------------------------------------

Ibrahim A

unread,
Aug 16, 2016, 1:58:29 PM8/16/16
to fltk.general
I guess I didn't get the tutorial correctly. I modified the code and I was able to generate the .h and .cxx files from the .fl source. but still get an error. I think this error is related to the fact the generated files are in the build folder but I don't know how to solve this issue. I now have these files:
build/myGUI.h
build/myGUI.cxx
build/libmyGUI.a

Here is the error and the modfied files (I also changed the file names ):
----------------------------------------------------------------------
output of running build/make  
----------------------------------------------------------------------
[100%] Linking CXX executable foo
CMakeFiles/foo.dir/foo.cxx.o: In function `main':
foo.cxx:(.text+0x11): undefined reference to `myGUI::myGUI()'
foo.cxx:(.text+0x1d): undefined reference to `myGUI::Show()'
foo.cxx:(.text+0x4f): undefined reference to `myGUI::~myGUI()'
foo.cxx:(.text+0x62): undefined reference to `myGUI::~myGUI()'
collect2: error: ld returned 1 exit status
make[2]: *** [foo] Error 1
make[1]: *** [CMakeFiles/foo.dir/all] Error 2
make: *** [all] Error 2
----------------------------------------------------------------------
src/foo.cxx
----------------------------------------------------------------------
#include "myGUI.h"
#include <iostream>
int main(  ){
    myGUI gui;
    gui.Show();
    Fl::run();
    std::cout<<" alles gut"<<std::endl;
    return 0;
}
----------------------------------------------------------------------
src/myGUI.fl
----------------------------------------------------------------------
# data file for the Fltk User Interface Designer (fluid)
version 1.0303 
header_name {.h} 
code_name {.cxx}
class myGUI {open} {
  Function {myGUI()} {open
  } {
    Fl_Window myWin {open xywh {65 52 590 440} type Single visible } {
      Fl_Button {} { label Quit xywh {225 250 120 40}
      }
      Fl_Box {} { label {FLTK} xywh {135 105 305 100} labelfont 9 labelsize 20 }
    }
  }
  Function {~myGUI()} {open } {}
  Function {Quit()} {open } {
    code {myWin->hide();} {}
  }
  Function {Show()} {open } {
    code {myWin->show();} {}
  }
----------------------------------------------------------------------
src/CMakeLists.txt
----------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.1)
PROJECT(foo)

FIND_PACKAGE(FLTK REQUIRED NO_MODULE)  
include_directories(${FLTK_INCLUDE_DIRS}) 
link_directories(${FLTK_LIBRARY_DIRS}) 
add_definitions(${FLTK_DEFINITIONS}) 

ADD_EXECUTABLE( foo foo.cxx ) 
FLTK_WRAP_UI( myGUI myGUI.fl ) # create variable myGUI_FLTK_UI_SRCS, myGUI.cxx, and myGUI.h files

ADD_LIBRARY(myGUI foo.cxx ${myGUI_FLTK_UI_SRCS}) 
ADD_DEPENDENCIES(foo myGUI)
TARGET_LINK_LIBRARIES( foo fltk ) 
----------------------------------------------------------------------
Your help shall be appreciated.

Albrecht Schlosser

unread,
Aug 16, 2016, 2:00:39 PM8/16/16
to fltkg...@googlegroups.com
On 16.08.2016 18:55 Ibrahim A wrote:

> I am trying to build another simple fltk example using cmake. I have two
> files foo.cxx and ui.fl in addition to the CMakeLists.txt. I tried to
> use FLTK_WRAP_UI but I get this error when I run make command:

FLTK_WRAP_UI is deprecated and may not work as expected.
It's an old CMake command(!) designed for FLTK 1.1.

> ------------------------------------------------------
> CMakeLists.txt
> ------------------------------------------------------
...
> ADD_EXECUTABLE( foo foo.cxx )
> FLTK_WRAP_UI( foo ui.fl )
>
> ADD_LIBRARY(ui foo.cxx ${ui_FLTK_UI_SRCS})
> ADD_DEPENDENCIES(foo ui)

Please read README.CMake.txt for information about using
fluid w/o FLTK_WRAP_UI. This is the preferred way for FLTK 1.3 and later.

And please note: FLTK's CMake support is not yet complete (it is
currently experimental) and may change in future releases (FLTK 1.4.0
and later).

Ibrahim A

unread,
Aug 16, 2016, 2:37:16 PM8/16/16
to fltk.general, Albrech...@online.de
Many thanks for your reply.  
>FLTK_WRAP_UI is deprecated and may not work as expected.
>It's an old CMake command(!) designed for FLTK 1.1.
It works, it generates the needed file 
>Please read README.CMake.txt for information about using
>fluid w/o FLTK_WRAP_UI. This is the preferred way for FLTK 1.3 and later. 
Could you please tell me what is wrong wit my code? 
Based on the example in the file I added this modification but still get the same error:
      target_include_directories(foo PUBLIC ${FLTK_INCLUDE_DIRS})
>And please note: FLTK's CMake support is not yet complete (it is
>currently experimental) and may change in future releases (FLTK 1.4.0
>and later).
Totally understood, it is just I think I am doing something wrong that any expert can figure it out easily. 
 

Michael Surette

unread,
Aug 16, 2016, 5:47:55 PM8/16/16
to fltkg...@googlegroups.com
On Tue, Aug 16, 2016 at 2:37 PM, Ibrahim A wrote:

> Totally understood, it is just I think I am doing something wrong that any
> expert can figure it out easily.

It may not be anything that you're doing. The FLTK_WRAP_UI function
is known not to work in CMake 3.4.x. I haven't tried any later
versions.

To see how FLTK builds it's examples with fluid code in them see the
FLTK_RUN_FLUID function in FLTK-Functions.cmake in the CMake directory
of a recent snapshot of FLTK. If you build FLTK with CMake then this
function is available for your use.

--
Mike

Greg Ercolano

unread,
Aug 16, 2016, 6:42:25 PM8/16/16
to fltkg...@googlegroups.com
On 08/16/16 09:55, Ibrahim A wrote:
> I noticed that the files ui.h and ui.cxx are not generated.
> When using cmake-gui, some fltk variables are missing e.g fluid executable. Any suggestion?

I can't answer to cmake, but you would need in your makefile somewhere
a way to invoke e.g. 'fluid -c ui.fl' to convert the ui.fl -> ui.{cxx,h} files.

How you would do this in cmake I don't know,
but the makefile rule would look something like this:

--- snip
.fl.cxx .fl.h: /path/to/fluid
echo Generating $@ and header from $<...
/path/to/fluid -c $<
--- snip


..and be sure .fl is a member of the .SUFFIXES, e.g.

.SUFFIXES: .0 .1 .3 .6 .c .cxx .mm .h .fl .man .o .z .exe

Albrecht Schlosser

unread,
Aug 16, 2016, 7:36:53 PM8/16/16
to fltkg...@googlegroups.com
On 16.08.2016 19:58 Ibrahim A wrote:
> I guess I didn't get the tutorial correctly. I modified the code and I
> was able to generate the .h and .cxx files from the .fl source. but
> still get an error. I think this error is related to the fact the
> generated files are in the build folder but I don't know how to solve
> this issue. I now have these files:
> build/myGUI.h
> build/myGUI.cxx
> build/libmyGUI.a
>
> Here is the error and the modfied files (I also changed the file names ):
> ----------------------------------------------------------------------
> output of running build/make
> ----------------------------------------------------------------------
> [100%] Linking CXX executable foo
> CMakeFiles/foo.dir/foo.cxx.o: In function `main':
> foo.cxx:(.text+0x11): undefined reference to `myGUI::myGUI()'
> foo.cxx:(.text+0x1d): undefined reference to `myGUI::Show()'
> foo.cxx:(.text+0x4f): undefined reference to `myGUI::~myGUI()'
> foo.cxx:(.text+0x62): undefined reference to `myGUI::~myGUI()'
> collect2: error: ld returned 1 exit status
> make[2]: *** [foo] Error 1
> make[1]: *** [CMakeFiles/foo.dir/all] Error 2
> make: *** [all] Error 2

You missed to add your lib (myGUI) to your executable, hence there
are undefined (missing) functions myGUI::*().

Here is my corrected version of your CMakeLists.txt file:

#----------------------------------------------------------------------
# src/CMakeLists.txt
#----------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
PROJECT(foo)

set (FLTK_DIR "../build/Debug")

FIND_PACKAGE(FLTK REQUIRED NO_MODULE)
include_directories(${FLTK_INCLUDE_DIRS})
link_directories(${FLTK_LIBRARY_DIRS})
add_definitions(${FLTK_DEFINITIONS})

FLTK_WRAP_UI( myGUI myGUI.fl ) # create variable myGUI_FLTK_UI_SRCS,
myGUI.cxx, and myGUI.h files

ADD_LIBRARY(myGUI foo.cxx ${myGUI_FLTK_UI_SRCS})

ADD_EXECUTABLE( foo foo.cxx )
TARGET_LINK_LIBRARIES( foo myGUI fltk )
#----------------------------------------------------------------------

Notes:

(1) as before I added my path to FLTK. YMMV.

(2) I reordered some statements for a more "logical" order:

(2a) FLTK_WRAP_UI
(2b) ADD_LIBRARY
(2c) ADD_EXECUTABLE
(2d) TARGET_LINK_LIBRARIES

(3) I added 'myGUI' to TARGET_LINK_LIBRARIES (see above)

(4) I removed 'ADD_DEPENDENCIES(foo myGUI)'. This statement is
redundant (the dependency is given implicitly in TARGET_LINK_LIBRARIES)

With these changes in place I got only one undefined reference:
myGUI::~myGUI().

This is because you declare a destructor in your .fl file, but you do
not define (implement) it:

> ----------------------------------------------------------------------
> src/myGUI.fl
> ----------------------------------------------------------------------
> # data file for the Fltk User Interface Designer (fluid)
> version 1.0303
> header_name {.h}
> code_name {.cxx}
> class myGUI {open} {
> Function {myGUI()} {open
> } {
> Fl_Window myWin {open xywh {65 52 590 440} type Single visible } {
> Fl_Button {} { label Quit xywh {225 250 120 40}
> }
> Fl_Box {} { label {FLTK} xywh {135 105 305 100} labelfont 9
> labelsize 20 }
> }
> }
> Function {~myGUI()} {open } {}

The declaration above is faulty. I just removed (commented out) that
statement (using a default d'tor) and everything worked.

The better way would be to define (implement) the d'tor, but I was too
lazy, leaving this up to you.

PS: are you German? ("alles gut") ;-)

Message has been deleted

Ibrahim A

unread,
Aug 17, 2016, 3:57:38 AM8/17/16
to fltk.general


Many thanks, Albrecht. As I said, there was something wrong I did ;). It was forgetting to add the generated library in the CMakeLists.txt file as you mentioned:
TARGET_LINK_LIBRARIES( foo fltk myGUI )  
I also corrected the code in the myGUI.fl
# data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cxx}
class myGUI {open} {
  Function {myGUI()} {open  } {
    Fl_Window myWin {open xywh {4343 331 590 440} type Single visible    } {
      Fl_Button {} {
        label Quit
        callback {Quit()} selected
        xywh {225 250 120 40}
      }
      Fl_Box {} {
        label FLTK
        xywh {135 105 305 100} labelfont 9 labelsize 20
      }
    }
  }
  Function {~myGUI()} {open  } {     } {}
  }
  Function {Quit()} {} {
    code {myWin->hide();} {}
  }
  Function {Show()} {} {
    code {myWin->show();} {}
  }
}
Thanks again to all participant. I appreciate your support.
Ibraheem
P.S: I am not German but I live currently in Germany.
Message has been deleted

Albrecht Schlosser

unread,
Aug 17, 2016, 6:50:58 AM8/17/16
to fltkg...@googlegroups.com
On 17.08.2016 12:31 Ibrahim A wrote:
> Same code was working fine but now when I tried it again I got this error:
> /src/foo.cxx: In function ‘int main()’:
> /src/foo.cxx:5:9: error: ‘class myGUI’ has no member named ‘Show’
> gui.Show();
> ^
> no system update and nothing new installed. What happened???

Hard to say. I'd look at the header file and/or the fluid file to see if
the declaration of Show() is missing or misspelled.

Ibrahim A

unread,
Aug 17, 2016, 6:59:56 AM8/17/16
to fltk.general
never mind, it was a stupid mistake in the fl file that I forgot to modify. Here are the final files contents:

----------------------------------------------------------------------
src/foo.cxx
----------------------------------------------------------------------
#include "myGUI.h"
int main(  ){
    myGUI gui;
    gui.Show();
    Fl::run();
    return 0;
}
----------------------------------------------------------------------
src/myGUI.fl
----------------------------------------------------------------------
 # data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cxx}
class myGUI {open
} {
  Function {myGUI()} {open
  } {
    Fl_Window myWin {open
      xywh {4128 135 590 440} type Single visible
    } {
      Fl_Button {} {
        label Quit
        callback {Quit();} selected
        xywh {225 250 120 40}
      }
      Fl_Box {} {
        label FLTK
        xywh {135 105 305 100} labelfont 9 labelsize 20
      }
    }
  }
  Function {~myGUI()} {open
  } {
    code {} {}
  }
  Function {Quit()} {open
  } {
    code {myWin->hide();} {}
  }
  Function {Show()} {open
  } {
    code {myWin->show();} {}
  }
}
----------------------------------------------------------------------
src/CMakeLists.txt
----------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.1)
PROJECT(foo)

FIND_PACKAGE(FLTK REQUIRED NO_MODULE)  
include_directories(${FLTK_INCLUDE_DIRS}) 
link_directories(${FLTK_LIBRARY_DIRS}) 
add_definitions(${FLTK_DEFINITIONS}) 

ADD_EXECUTABLE( foo foo.cxx ) 
FLTK_WRAP_UI( myGUI myGUI.fl ) # create variable myGUI_FLTK_UI_SRCS, myGUI.cxx, and myGUI.h files

ADD_LIBRARY(myGUI foo.cxx ${myGUI_FLTK_UI_SRCS}) 
ADD_DEPENDENCIES(foo myGUI)
TARGET_LINK_LIBRARIES( foo fltk myGUI) 
----------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages