Theodore
Theodore

Reputation: 309

FLTK - can't compile with g++

After installing FLTK 1.4 library on Manjaro Linux I compiled it successfully with "fltk-config -compile hello.cpp"

However, it seems I can't compile it with g++:

g++ hello.cpp -o hello -I/usr/local/include -L/usr/local/lib -lfltk -lXext -lX11 -lm -ldl

The error message:

/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_X11_Screen_Driver.cxx.o): in function `Fl_X11_Screen_Driver::init()':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/X11/Fl_X11_Screen_Driver.cxx:312: undefined reference to `XineramaIsActive'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/X11/Fl_X11_Screen_Driver.cxx:313: undefined reference to `XineramaQueryScreens'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_x.cxx.o): in function `open_display_i(_XDisplay*)':
/home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:695: undefined reference to `XFixesQueryExtension'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_x.cxx.o): in function `xrender_supported()':
/home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:2342: undefined reference to `XRenderQueryExtension'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_x.cxx.o): in function `Fl_X::make_xid(Fl_Window*, XVisualInfo*, unsigned long)':
/home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:2702: undefined reference to `XFixesSelectSelectionInput'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:2704: undefined reference to `XFixesSelectSelectionInput'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_x.cxx.o): in function `Fl_X11_Window_Driver::set_cursor(Fl_RGB_Image const*, int, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:2978: undefined reference to `XcursorImageCreate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:3027: undefined reference to `XcursorImageLoadCursor'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/Fl_x.cxx:3031: undefined reference to `XcursorImageDestroy'
/usr/bin/ld: /usr/bin/ld: DWARF error: could not find variable specification at offset 43e4
/usr/bin/ld: DWARF error: could not find variable specification at offset 43f1
/usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::set_fonts(char const*)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:352: undefined reference to `FcInit'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:363: undefined reference to `FcPatternCreate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:364: undefined reference to `FcObjectSetBuild'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:367: undefined reference to `FcFontList'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:370: undefined reference to `FcPatternDestroy'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:371: undefined reference to `FcObjectSetDestroy'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:393: undefined reference to `FcNameUnparse'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:439: undefined reference to `FcFontSetDestroy'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `fontopen(char const*, double, bool, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:532: undefined reference to `FcPatternCreate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:567: undefined reference to `FcPatternAddString'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:586: undefined reference to `FcPatternAddString'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:590: undefined reference to `FcPatternAddInteger'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:591: undefined reference to `FcPatternAddInteger'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:592: undefined reference to `FcPatternAddDouble'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:593: undefined reference to `FcPatternAddString'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:599: undefined reference to `FcMatrixRotate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:600: undefined reference to `FcPatternAddMatrix'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:604: undefined reference to `FcPatternAddBool'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:605: undefined reference to `FcPatternAddBool'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:612: undefined reference to `XftFontMatch'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:649: undefined reference to `XftFontOpenPattern'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:653: undefined reference to `XftFontOpen'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:657: undefined reference to `FcPatternDestroy'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:671: undefined reference to `FcPatternDestroy'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:690: undefined reference to `XftFontOpenXlfd'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `utf8extents(Fl_Xlib_Font_Descriptor*, char const*, int, _XGlyphInfo*)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:739: undefined reference to `XftTextExtents32'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `fl_xft_width(Fl_Font_Descriptor*, unsigned int*, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:763: undefined reference to `XftTextExtents32'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::draw_unscaled(char const*, int, int, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:809: undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:812: undefined reference to `XftDrawChange'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:816: undefined reference to `XftDrawSetClip'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:832: undefined reference to `XftDrawString32'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::drawUCS4(void const*, int, int, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:855: undefined reference to `XftDrawCreate'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:858: undefined reference to `XftDrawChange'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:862: undefined reference to `XftDrawSetClip'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:874: undefined reference to `XftDrawString32'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::rtl_draw_unscaled(char const*, int, int, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:894: undefined reference to `FcUtf8Len'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:909: undefined reference to `FcUtf8ToUcs4'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::get_font_sizes(int, int*&)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:938: undefined reference to `XftListFonts'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:952: undefined reference to `FcPatternGetDouble'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:957: undefined reference to `FcFontSetDestroy'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_font_xft.cxx.o): in function `Fl_Xlib_Graphics_Driver::destroy_xft_draw(unsigned long)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_font_xft.cxx:1021: undefined reference to `XftDrawChange'
/usr/bin/ld: /usr/local/lib/libfltk.a(Fl_Xlib_Graphics_Driver_image.cxx.o): in function `Fl_Xlib_Graphics_Driver::scale_and_render_pixmap(unsigned long, int, double, double, int, int, int, int, int, int)':
/home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:782: undefined reference to `XRenderFindStandardFormat'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:783: undefined reference to `XRenderFindStandardFormat'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:784: undefined reference to `XRenderFindVisualFormat'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:785: undefined reference to `XRenderCreatePicture'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:786: undefined reference to `XRenderCreatePicture'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:794: undefined reference to `XRenderSetPictureClipRegion'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:802: undefined reference to `XRenderSetPictureTransform'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:804: undefined reference to `XRenderComposite'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:806: undefined reference to `XRenderFreePicture'
/usr/bin/ld: /home/theo/1. Programming/2. Libraries/fltk/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx:807: undefined reference to `XRenderFreePicture'
collect2: error: ld returned 1 exit status

hello.cpp is the one from the documentation: https://fltk.gitlab.io/fltk/basics.html

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv)
{
    Fl_Window *window = new Fl_Window(340, 180);
    Fl_Box *box = new Fl_Box(20, 40, 300, 100, "Hello, World!");
    box->box(FL_UP_BOX);
    box->labelfont(FL_BOLD + FL_ITALIC);
    box->labelsize(36);
    box->labeltype(FL_SHADOW_LABEL);
    window->end();
    window->show(argc, argv);
    return Fl::run();
}

Can someone tell me what I should add or change?

Thanks!

Edit: Another command that works to compile is:

g++ hello.cpp -o hello `fltk-config --ldflags`

Edit2: There are many more things to add to the g++ command so maybe it's not worth typing them manully. Using "fltk-config --compile test.cpp" seems to be the most convenient way. And the output shows this:

/usr/bin/c++ -I/usr/local/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o 'test' 'test.cpp' /usr/local/lib/libfltk.a -lm -lX11 -lXext -lpthread -lXinerama -lXfixes -lXcursor -lXft -lXrender -lm -lfontconfig -ldl

Edit3: I found this post where it explains how to compile the first example from Programming Principles and Practice, what I was actually trying to do. https://groups.google.com/g/ppp-public/c/BtlzdWGuQpQ

Edit4: I talked extensively with the FLTK team that was kind enough to explain different scenarios of how to install and use "fltk-config" script that knows how to link all the libs it needs. So a compile command would be something like this:

g++ -w -Wall -std=c++14 ../../Graph_lib/Graph.cpp ../../Graph_lib/Window.cpp ../../Graph_lib/GUI.cpp ../../Graph_lib/Simple_window.cpp 15_classes.cpp 15.9.cpp `/home/Dev/fltk-1.4.0/bin/fltk-config --cxxflags --ldflags --use-images` -o 15.9.bin

The discussion is here: https://groups.google.com/g/fltkgeneral/c/gAuM_wxIc_o Warning: it's loong, but worth it!

Upvotes: 2

Views: 1358

Answers (3)

Koray
Koray

Reputation: 1

You can use "fltk-config" shell script which comes with FLTK source code. As the fltk-config command detects all the required environment variables to compile/link your source code, you don't even need to specify the compiler/linker commands, nor the $CXX flags.

The following command is sufficient to compile/link your source code:

fltk-config --compile hello_world.cxx

And if your source code makes use of FLTK image libraries, you just need to add the "--use-images" flag as follows:

fltk-config --use-images --compile hello_world.cxx

You can also have a look at the "fltk-config" shell script code to see what flags it uses behind the scenes:

cat $(whereis fltk-config) | less

Upvotes: 0

Mantu
Mantu

Reputation: 149

I am also getting same error but for me by linking below libs error got resolve. Here is the full command.

g++ helloWorld.cpp -o hello -Ifltk-1.3.6 -Lfltk-1.3.6/lib -lfltk -lX11 -lXfixes -lXext -ldl -lXext -lpthread -lXinerama -lXcursor -lXft -lXrender -lm -lfontconfig

BR,

Upvotes: 1

cup
cup

Reputation: 8237

You probably need the xinerama package. The full list of packages you need to get is

  • libglu1-mesa-dev
  • libice-dev
  • libjpeg-dev - this may be libjpeg62-dev or some other number
  • libpng-dev - this may be libpng12-dev or some other number
  • libx11-dev
  • libxcursor-dev
  • libxext-dev
  • libxft-dev
  • libxinerama-dev
  • libxi-dev
  • mesa-common-dev
  • zlib1g-dev - it is a one after the b: not an L

If you are running one of the older builds, you may need to modify the distribution makefile before running configure and make

  • Look for LDLIBS and add -lfontconfig -lXrender
  • Look for GLDLIBS and add -lfontconfig -lXrender -lfreetype

Otherwise you will get an undefined reference to symbol FcInit in font.o

Upvotes: 0

Related Questions