-1

I'm fairly new to C++ / CMake, but I'd like to create a project with FLTK using CMAKE and CONAN as package manager. I'm using Windows 11, but trying to get it to run under WSL (Ubuntu 20.04). My WSL-version supports GUI applications.

When I install everything without Conan and compile the official "fltk-hello-world" from the command line using fltk-config, everything works okay. However, when I try to set it up using Conan und Cmake I get following errors:

/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Font_Descriptor::Fl_Font_Descriptor(char const*, int, int)':
fl_font.cxx:(.text+0x232): undefined reference to `XftFontOpenXlfd'
/usr/bin/ld: fl_font.cxx:(.text+0x47e): undefined reference to `XftFontMatch'
/usr/bin/ld: fl_font.cxx:(.text+0x48f): undefined reference to `XftFontOpenPattern'
/usr/bin/ld: fl_font.cxx:(.text+0x4e1): undefined reference to `XftFontOpen'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::width(char const*, int)':
fl_font.cxx:(.text+0x954): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::width(unsigned int)':
fl_font.cxx:(.text+0xa5e): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::text_extents(char const*, int, int&, int&, int&, int&)':
fl_font.cxx:(.text+0xb07): undefined reference to `XftTextExtents32'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x1140): undefined reference to `XftDrawChange'
/usr/bin/ld: fl_font.cxx:(.text+0x1176): undefined reference to `XftDrawSetClip'
/usr/bin/ld: fl_font.cxx:(.text+0x1209): undefined reference to `XftDrawString32'
/usr/bin/ld: fl_font.cxx:(.text+0x12d9): undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `Fl_Xlib_Graphics_Driver::rtl_draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x149b): undefined reference to `XftTextExtents32'
/usr/bin/ld: fl_font.cxx:(.text+0x14cc): undefined reference to `XftDrawChange'
/usr/bin/ld: fl_font.cxx:(.text+0x1502): undefined reference to `XftDrawSetClip'
/usr/bin/ld: fl_font.cxx:(.text+0x1595): undefined reference to `XftDrawString32'
/usr/bin/ld: fl_font.cxx:(.text+0x15f9): undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/bfl/.conan/data/fltk/1.3.8/_/_/package/b6898709771003e31b8ea824ee836cf119580bd8/lib/libfltk.a(fl_font.cxx.o): in function `fl_destroy_xft_draw(unsigned long)':
fl_font.cxx:(.text+0x10d9): undefined reference to `XftDrawChange'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello.dir/build.make:84: bin/hello] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

So I assume that i am probably not linking XFT? But I am not sure how to do that, do I need to include the correct name in target-link-libraries? My Cmake-File looks like this:

cmake_minimum_required(VERSION 3.2.3)

project(Hello VERSION 0.1.0)

set(EXECUTABLE_NAME hello)
set(EXE_SOURCES hello.cc)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${EXECUTABLE_NAME} ${EXE_SOURCES})

target_include_directories(hello PUBLIC ${FLTK_INCLUDE_DIRS})

target_link_libraries(hello
    ${CONAN_LIBS})

I'm grateful for any suggestion.

Thanks,

GB

  • Did you explicitly enable `USE_XFT` with a header or something? The conan version currently doesn't set that option during compilation or model the xft dependency that would need. – PeterT Jun 11 '22 at 18:56
  • Hm, nevermind seems like the FLTK cmake file tries to auto-detect it during compilation, but conan is oblivious to the result of that detection. So if the conan fltk package was compiled on a machine with xft installed then it might automatically enable those code paths, but the conan recipe does not reflect that – PeterT Jun 11 '22 at 19:13
  • So unless you want to fix the fltk conan recipe your best bet for now is probably just to manually add `xft` to `target_link_libraries` and make sure you have the package installed in WSL (or add xft to the conan dependencies) – PeterT Jun 11 '22 at 19:15
  • Thanks for the Answer. So when I include in the project and just for the sake of testing I comment out all the rest, but I cout "XFT_MAJOR" (which is a defined constant in that header), it compiles and works. So it appears as Xft can be found/linked and maybe I'm lacking some libraries? – GreenButterfly Jun 11 '22 at 19:23
  • Regarding xft in target_link_libraries: I tried that, but then make complains that it can't find '-lxft". Do you know where I can find the correct name for that? – GreenButterfly Jun 11 '22 at 19:29
  • Capitilization matters, so it might be `Xft` – PeterT Jun 11 '22 at 19:33
  • Now it works :) It took a while, but I had to add Xft after ${CONAN_LIBS} in the target_link_libraries call. It confuses me as I thought the order does not matter. Do you want to post your comment as an answer? – GreenButterfly Jun 11 '22 at 19:46

1 Answers1

1

The conan recipe for fltk does not correctly deal with the cmake system of fltk.

Fltk auto-detects if the system it compiles on has Xft. If it does, then it enables the HAS_XFT variable and compiles some code into the library that uses it.

Conan does not pick up on this and doesn't add Xft to the dependent libraries.

The easiest way around this bug is to manually add the xft dependency. If you have libXft installed on your system you can simply add an entry of Xft to the target_link_libraries of the target that uses fltk.

Like this:

target_link_libraries(hello ${CONAN_LIBS} Xft)

PeterT
  • 7,981
  • 1
  • 26
  • 34