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") ;-)