在 Manjaro Linux 上安装 FLTK 1.4 库后,我使用“fltk-config -compile hello.cpp”成功编译它
但是,我似乎无法用g++编译它:
g++ hello.cpp -o hello -I/usr/local/include -L/usr/local/lib -lfltk -lXext -lX11 -lm -ldl
错误信息:
/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 是文档中的: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();
}
有人可以告诉我应该添加或更改什么吗?
谢谢!
编辑: 另一个可以编译的命令是:
g++ hello.cpp -o hello `fltk-config --ldflags`
编辑2: 还有很多东西需要添加到 g++ 命令中,因此也许不值得手动输入它们。 使用“fltk-config --compile test.cpp”似乎是最方便的方法。输出显示如下:
/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
编辑3: 我发现这篇文章解释了如何编译《编程原理与实践》中的第一个示例,这是我实际上想要做的。 https://groups.google.com/g/ppp-public/c/BtlzdWGuQpQ
编辑4: 我与 FLTK 团队进行了广泛的交谈,他们很友善地解释了如何安装和使用“fltk-config”脚本的不同场景,该脚本知道如何链接它需要的所有库。所以编译命令会是这样的:
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
讨论在这里: https://groups.google.com/g/fltkgeneral/c/gAuM_wxIc_o 警告:它很长,但值得!
我也遇到了同样的错误,但对我来说,通过链接下面的库错误得到了解决。 这是完整的命令。
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,
您可能需要 xinerama 软件包。您需要获取的软件包的完整列表是
如果您正在运行较旧的版本之一,则可能需要在运行configure和make之前修改发行版makefile
否则你将在 font.o 中得到对符号 FcInit 的未定义引用
您可以使用FLTK源代码附带的“fltk-config”shell脚本。 由于 fltk-config 命令会检测编译/链接源代码所需的所有环境变量,因此您甚至不需要指定编译器/链接器命令,也不需要指定 $CXX 标志。
以下命令足以编译/链接您的源代码:
fltk-config --compile hello_world.cxx
如果您的源代码使用 FLTK 图像库,您只需添加“--use-images”标志,如下所示:
fltk-config --use-images --compile hello_world.cxx
您还可以查看“fltk-config”shell 脚本代码,了解它在幕后使用的标志:
cat $(whereis fltk-config) | less