deech / fltkhs

Haskell bindings to FLTK GUI toolkit.
MIT License
190 stars 24 forks source link

Type error when building fltkhs-demos: [Char] vs Text #64

Closed conal closed 7 years ago

conal commented 7 years ago

On Mac OS 10.11.6:

bash-3.2$ cabal update
Downloading the latest package list from hackage.haskell.org
bash-3.2$ cabal install fltkhs-demos
Resolving dependencies...
Downloading fltkhs-0.5.3.4...
Configuring fltkhs-0.5.3.4...
Building fltkhs-0.5.3.4...
Installed fltkhs-0.5.3.4
Downloading fltkhs-demos-0.0.0.7...
Configuring fltkhs-demos-0.0.0.7...
Building fltkhs-demos-0.0.0.7...
Failed to install fltkhs-demos-0.0.0.7
Build log ( /Users/conal/.cabal/logs/ghc-8.0.2/fltkhs-demos-0.0.0.7-Ftx2BvJpVHMA8mmEQdEyxx.log ):
cabal: Entering directory '/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/cabal-tmp-16244/fltkhs-demos-0.0.0.7'
[1 of 1] Compiling Main             ( /var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/cabal-tmp-16244/fltkhs-demos-0.0.0.7/dist/setup/setup.hs, /var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/cabal-tmp-16244/fltkhs-demos-0.0.0.7/dist/setup/Main.o )
Linking /var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/cabal-tmp-16244/fltkhs-demos-0.0.0.7/dist/setup/setup ...
Configuring fltkhs-demos-0.0.0.7...
Building fltkhs-demos-0.0.0.7...
Preprocessing executable 'fltkhs-threads' for fltkhs-demos-0.0.0.7...
[1 of 1] Compiling Main             ( src/Examples/threads.hs, dist/build/fltkhs-threads/fltkhs-threads-tmp/Main.o )

src/Examples/threads.hs:25:97: error:
    • Couldn't match type ‘[Char]’
                     with ‘text-1.2.2.1:Data.Text.Internal.Text’
      Expected type: Maybe text-1.2.2.1:Data.Text.Internal.Text
        Actual type: Maybe [Char]
    • In the second argument of ‘buttonNew’, namely
        ‘(Just "start background thread")’
      In a stmt of a 'do' block:
        startButton <- buttonNew
                         (Rectangle (Position (X 15) (Y 10)) (Size (Width 230) (Height 25)))
                         (Just "start background thread")
      In the expression: [...]

Plus five more similar errors.

conal commented 7 years ago

BTW, I'm resurrecting the declarative, composable GUIs from Eros, and fltkhs seems a good candidate to build on.

One use will be to control GPU shaders generated from simple Haskell code via compiling to categories, reproducing Pan and Vertigo in a much simpler way, with a nicer programming interface.

Does the OpenGL support in fltkhs work with shaders?

deech commented 7 years ago

Thanks for trying it out!

Unfortunately the Hackage versions of the demos are deprecated and no longer being updated. Please clone https://github.com/deech/fltkhs-demos and at the root of the directory do stack build --flag fltkhs:bundled. Also although cabal might work I've only tested it with stack.

I don't know much about graphics programming with OpenGL but I have a starter set of demos here https://github.com/deech/fltkhs-gl-demos. It's installable with stack build --flag fltkhs:bundled --flag fltkhs:opengl. I'll look into the shaders later today.

conal commented 7 years ago

Thanks for the tips. A new attempt (below) leads to Undefined symbols for architecture x86_64: "Fl_Browser::textsize(int)". Details below. I tried with fltkhs-gl-demos as well and got the same error.

bash-3.2$ pwd
/Users/conal/git-repos/fltkhs-demos
bash-3.2$ git pull
Already up-to-date.
bash-3.2$ stack install --flag fltkhs:bundled
Cabal file warning in /Users/conal/git-repos/fltkhs-demos/fltkhs-demos.cabal: Unknown fields: extra-source-files (line 371)
Fields allowed in this section:
    main-is, buildable, build-tools, build-depends, cpp-options,
    cc-options, ld-options, pkgconfig-depends, frameworks,
    extra-framework-dirs, c-sources, js-sources, default-language,
    other-languages, default-extensions, other-extensions, extensions,
    extra-libraries, extra-ghci-libraries, extra-lib-dirs, includes,
    install-includes, include-dirs, hs-source-dirs, other-modules,
    ghc-prof-options, ghcjs-prof-options, ghc-shared-options,
    ghcjs-shared-options, ghc-options, ghcjs-options, jhc-options,
    hugs-options, nhc98-options
fltkhs-0.5.3.4: configure
Progress: 0/2stack build --flag fltkhs:bundled --flag fltkhs:opProgress: 1/2user interrupt
bash-3.2$ stack build --flag fltkhs:bundled --flag fltkhs:opengl
Cabal file warning in /Users/conal/git-repos/fltkhs-demos/fltkhs-demos.cabal: Unknown fields: extra-source-files (line 371)
Fields allowed in this section:
    main-is, buildable, build-tools, build-depends, cpp-options,
    cc-options, ld-options, pkgconfig-depends, frameworks,
    extra-framework-dirs, c-sources, js-sources, default-language,
    other-languages, default-extensions, other-extensions, extensions,
    extra-libraries, extra-ghci-libraries, extra-lib-dirs, includes,
    install-includes, include-dirs, hs-source-dirs, other-modules,
    ghc-prof-options, ghcjs-prof-options, ghc-shared-options,
    ghcjs-shared-options, ghc-options, ghcjs-options, jhc-options,
    hugs-options, nhc98-options
fltkhs-0.5.3.4: configure
fltkhs-0.5.3.4: build
Progress: 1/2
--  While building package fltkhs-0.5.3.4 using:
      /private/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/stack26737/fltkhs-0.5.3.4/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 2
    Logs have been written to: /Users/conal/git-repos/fltkhs-demos/.stack-work/logs/fltkhs-0.5.3.4.log

    [1 of 2] Compiling Main             ( /private/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/stack26737/fltkhs-0.5.3.4/Setup.hs, /private/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/stack26737/fltkhs-0.5.3.4/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/Main.o )
    [2 of 2] Compiling StackSetupShim   ( /Users/conal/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /private/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/stack26737/fltkhs-0.5.3.4/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/StackSetupShim.o )
    Linking /private/var/folders/wx/m2wn7shj0gn4q_y_wnybcsqh0000gn/T/stack26737/fltkhs-0.5.3.4/.stack-work/dist/x86_64-osx/Cabal-1.24.2.0/setup/setup ...
    Building bundled FLTK
    checking build system type... x86_64-apple-darwin15.6.0
    checking host system type... x86_64-apple-darwin15.6.0
    checking for gcc... gcc
    checking whether the C compiler works... yes
    ..
    checking if toolchain supports sections... no

    Configuration Summary
    -------------------------------------------------------------------------
        Directories: prefix=/Users/conal/git-repos/fltkhs-demos/.stack-work/install/x86_64-osx/lts-8.13/8.0.2/lib/fltk-bundled
                     bindir=${exec_prefix}/bin
                     datadir=${datarootdir}
                     datarootdir=${prefix}/share
                     exec_prefix=${prefix}
                     includedir=${prefix}/include
                     libdir=${exec_prefix}/lib
                     mandir=${datarootdir}/man
           Graphics: Quartz
    Image Libraries: JPEG=Builtin
                     PNG=Builtin
                     ZLIB=Builtin
        Large Files: YES
             OpenGL: YES
            Threads: YES
    configure: creating ./config.status
    config.status: creating makeinclude
    config.status: creating fltk.list
    config.status: creating fltk-config
    config.status: creating fltk.spec
    config.status: creating FL/Makefile
    config.status: creating config.h
    config.status: creating FL/abi-version.h
    === making jpeg ===
    Compiling jaricom.c...
    Compiling jcapimin.c...
...
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libfltk.a(utf8Utils.o) has no symbols
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libfltk.a(utf8Wrap.o) has no symbols
    g++ -L. -dynamiclib -lc -o libfltk.1.3.dylib ...
    Compiling forms_compatability.cxx...
    Compiling forms_bitmap.cxx...
...
    === installing test ===
    Installing example programs to /Users/conal/git-repos/fltkhs-demos/.stack-work/install/x86_64-osx/lts-8.13/8.0.2/lib/fltk-bundled/share/doc/fltk/examples...
    === installing documentation ===
    Installing documentation files in /Users/conal/git-repos/fltkhs-demos/.stack-work/install/x86_64-osx/lts-8.13/8.0.2/lib/fltk-bundled/share/doc/fltk ...
    Installing man pages in /Users/conal/git-repos/fltkhs-demos/.stack-work/install/x86_64-osx/lts-8.13/8.0.2/lib/fltk-bundled/share/man ...
    Running autoconf ...
    Configuring fltkhs-0.5.3.4...
    : WARNING: unrecognized options: --with-compiler
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
...
    config.status: creating fltkhs.buildinfo
    config.status: creating config.h
    : WARNING: unrecognized options: --with-compiler
    ==Compiling C bindings==
    *** Compiling glC.cpp...
    *** Compiling glutC.cpp...
    *** Compiling Fl_Gl_WindowC.cpp...
    *** Compiling Fl_Menu_ButtonC.cpp...
    *** Compiling Fl_PositionerC.cpp...
...
    *** Compiling Fl_Value_InputC.cpp...
    *** Compiling Fl_WidgetC.cpp...
    *** Compiling Fl_WindowC.cpp...
    *** Compiling Fl_WizardC.cpp...
    *** Linking libfltkc.a...
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../c-lib/libfltkc.a(fl_utf8C.o) has no symbols
    *** Linking libfltkc-dyn.dylib...
    Undefined symbols for architecture x86_64:
      "Fl_Browser::textsize(int)", referenced from:
          _Fl_Browser_set_textsize in Fl_BrowserC.o
          Fl_File_Browser::textsize(int) in Fl_File_BrowserC.o
          _Fl_Hold_Browser_set_textsize in Fl_Hold_BrowserC.o
          _Fl_Multi_Browser_set_textsize in Fl_Multi_BrowserC.o
          _Fl_Select_Browser_set_textsize in Fl_Select_BrowserC.o
      "Fl_Gl_Window::pixels_per_unit()", referenced from:
          _Fl_Gl_Window_pixels_per_unit in Fl_Gl_WindowC.o
          Fl_Gl_Window::pixel_h() in Fl_Gl_WindowC.o
          Fl_Gl_Window::pixel_w() in Fl_Gl_WindowC.o
      "Fl_RGB_Image::Fl_RGB_Image(unsigned char const*, int, int, int, int)", referenced from:
          _Fl_RGB_Image_New in Fl_RGB_ImageC.o
          _Fl_RGB_Image_New_With_D in Fl_RGB_ImageC.o
          _Fl_RGB_Image_New_With_LD in Fl_RGB_ImageC.o
          _Fl_RGB_Image_New_With_D_LD in Fl_RGB_ImageC.o
      "Fl_Surface_Device::default_surface()", referenced from:
          Fl_Surface_Device::surface() in Fl_DeviceC.o
          Fl_Surface_Device::surface() in Fl_Paged_DeviceC.o
          Fl_Surface_Device::surface() in Fl_PrinterC.o
      "Fl_Graphics_Driver::draw_scaled(Fl_Image*, int, int, int, int)", referenced from:
          _fl_Graphics_Driver_draw_scaled in Fl_DeviceC.o
      "Fl::abi_version()", referenced from:
          _Fl_abi_version in Fl_C.o
          Fl::abi_check(int) in Fl_C.o
      "Fl::api_version()", referenced from:
          _Fl_api_version in Fl_C.o
      "Fl::set_box_color(unsigned int)", referenced from:
          _Fl_set_box_color in Fl_C.o
      "Fl::use_high_res_GL_", referenced from:
          Fl::use_high_res_GL(int) in Fl_C.o
          Fl::use_high_res_GL() in Fl_C.o
      "Fl::box_color(unsigned int)", referenced from:
          _Fl_box_color in Fl_C.o
      "Fl_Image::fail()", referenced from:
          _Fl_Image_fail in Fl_ImageC.o
      "Fl_Image::Fl_Image(int, int, int)", referenced from:
          Fl_Bitmap::Fl_Bitmap(char const*, int, int) in Fl_BitmapC.o
          Fl_Bitmap::Fl_Bitmap(unsigned char const*, int, int) in Fl_BitmapC.o
          Fl_DerivedImage::Fl_DerivedImage(int, int, int, fl_Image_Virtual_Funcs*) in Fl_ImageC.o
          Fl_Pixmap::Fl_Pixmap(char const* const*) in Fl_PixmapC.o
          Fl_Pixmap::Fl_Pixmap(unsigned char const* const*) in Fl_PixmapC.o
      "Fl_Menu_::setonly(Fl_Menu_Item*)", referenced from:
          _Fl_Menu__set_only in Fl_Menu_C.o
      "_aglChoosePixelFormat", referenced from:
          Fl_Gl_Choice::find(int, int const*) in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglCreateContext", referenced from:
          fl_create_gl_context(Fl_Window*, Fl_Gl_Choice const*, int) in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglDestroyContext", referenced from:
          fl_delete_gl_context(__AGLContextRec*) in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglEnable", referenced from:
          Fl_Gl_Window::make_current() in libfltk_gl.a(Fl_Gl_Window.o)
          fl_create_gl_context(Fl_Window*, Fl_Gl_Choice const*, int) in libfltk_gl.a(Fl_Gl_Choice.o)
          fl_set_gl_context(Fl_Window*, __AGLContextRec*) in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglGetCurrentContext", referenced from:
          fl_no_gl_context() in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglSetCurrentContext", referenced from:
          fl_set_gl_context(Fl_Window*, __AGLContextRec*) in libfltk_gl.a(Fl_Gl_Choice.o)
          fl_no_gl_context() in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglSetInteger", referenced from:
          Fl_Gl_Window::make_current() in libfltk_gl.a(Fl_Gl_Window.o)
          fl_create_gl_context(Fl_Window*, Fl_Gl_Choice const*, int) in libfltk_gl.a(Fl_Gl_Choice.o)
          fl_set_gl_context(Fl_Window*, __AGLContextRec*) in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglSetWindowRef", referenced from:
          fl_create_gl_context(Fl_Window*, Fl_Gl_Choice const*, int) in libfltk_gl.a(Fl_Gl_Choice.o)
          fl_set_gl_context(Fl_Window*, __AGLContextRec*) in libfltk_gl.a(Fl_Gl_Choice.o)
          fl_no_gl_context() in libfltk_gl.a(Fl_Gl_Choice.o)
      "_aglSwapBuffers", referenced from:
          Fl_Gl_Window::swap_buffers() in libfltk_gl.a(Fl_Gl_Window.o)
      "_aglUpdateContext", referenced from:
          Fl_Gl_Window::resize(int, int, int, int) in libfltk_gl.a(Fl_Gl_Window.o)
      "_fl_local_alt", referenced from:
          _Fl_local_alt in Fl_C.o
      "_fl_local_ctrl", referenced from:
          _Fl_local_ctrl in Fl_C.o
      "_fl_local_meta", referenced from:
          _Fl_local_meta in Fl_C.o
      "_fl_local_shift", referenced from:
          _Fl_local_shift in Fl_C.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [libfltkc-dyn.dylib] Error 1
    make: *** [src] Error 2
bash-3.2$ 
deech commented 7 years ago

Wow, that's a new one on me. I just tried it on mine and it worked. So far the only difference I can see is that I'm running Sierra 10.12.3. Could you attach the log file for the build? It should be in ./fltkhs-demos/.stack-work/logs/fltkhs-0.5.3.4.log. Thanks for your patience!

conal commented 7 years ago

Attached: fltkhs-0.5.3.4.log.txt. (I added a ".txt" extension so that GitHub would allow the attachment.)

deech commented 7 years ago

I think I see what's going on. I'm guessing you have an older version of FLTK (possibly 1.3.3) already on your system. You can verify this by running fltk-config --version. The functions it is unable to find were only added in the latest version. Additionally there's a bug in the bundled build where the shared version of the C bindings are trying to link against the old FLTK shared library on your system rather than the bundled version that was just built.

If I'm right I think the easiest workaround is to delete the system-wide installation . If you'd rather not delete you can try upgrading it to 1.3.4. If brew doesn't have 1.3.4 (on my version it does) I have instructions on compiling it manually.

If either of those work for you I'll fix and release a new version as soon as I can.

conal commented 7 years ago

With this help, I got there, with a few bumps along the way.

I brew-upgraded to 1.3.4, but fltk-config still said "1.3.3". I brew-uninstalled fltk, but fltk-config wass still there and reported "1.3.3". I did rm `which fltk-config`, and reinstalled fltk, but then I had no fltk-config, and I didn't know how to get it back. Retried stack-building fltkhs-demos, but got the same "Fl_Browser::textsize(int)" error. Brew-uninstalled again.

I followed your instructions for manually building fltk:

$ wget http://fltk.org/pub/fltk/1.3.4/fltk-1.3.4-1-source.tar.gz
$ tar -zxf fltk-1.3.4-1-source.tar.gz
$ cd fltk-1.3.4-1
$ ./configure --enable-gl --enable-shared --enable-localjpeg --enable-localzlib --enable-localpng
$ make
$ sudo make install
$ fltk-config --version
1.3.4-1

Okay! I hope I've not made it too difficult to upgrade fltk via brew later.

Tried again to install fltkhs-demos. Worked! Then tried fltkhs-gl-demos. Also worked. In the cube demo, the cube moves only when the mouse moves. Intentional?

Next I'll look through the fltkhs-demos code to see what I can learn.

Thanks very much for the help!

deech commented 7 years ago

That's awesome! I'll address the install issues on OSX. That ultimate goal is an easy install so I appreciate you troubleshooting.

The cube demo should just move on it's own. I'll look into that as well.

Also FYI I have a skeleton project that is intended a starting point for a FLTKHS app. It takes care of some annoying build configuration.

deech commented 7 years ago

One other thing, if you ever need to get rid of the manually compiled version you can do make uninstall in the root of the source directory. It remembers where it put libs/headers and removes them.

conal commented 7 years ago

Cool. Thanks for the skeleton project. And for the make uninstall tip.