Home > Enterprise >  Building FLTK Project with CMAKE/CONAN
Building FLTK Project with CMAKE/CONAN

Time:06-12

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

CodePudding user response:

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)

  • Related