为了尝试 FLTK,我有以下文件结构:
project
|--main.cc
|--include
| |--FL
| | |--all FLTK header files
|--lib
| |--libfltk.a
| |--other fltk libraries
main.cc 中包含以下内容:
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main()
{
Fl_Window window(200, 200, "Window title");
Fl_Box box(0,0,200,200,"Hello, World!");
window.show();
return Fl::run();
}
现在当我运行时:
g++ -std=c++11 -c -o main.o main.cc -I include
g++ -std=c++11 -o main.exe main.o -L lib -lfltk
第二次调用 g++ 后出现一大堆错误:
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0xf3): undefined reference to `CreateDIBSection@24'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x1cf): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x258): undefined reference to `CreateBitmap@20'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2a6): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$_ZL13image_to_iconPK12Fl_RGB_Imagebii+0x2b1): undefined reference to `DeleteObject@4'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x5b): undefined reference to `OleUninitialize@0'
lib/libfltk.a(Fl.o):Fl.cxx:(.text$__tcf_1+0x83): undefined reference to `RestoreDC@8'
etc ...
当我尝试链接其他 FLTK 库时,结果是相同的。谁能帮我解决这个问题吗?
我使用 Windows 中的 gcc 和 MingW。
最佳答案
要解决此类问题,需要借助fltk-config
脚本。因此,只需向编译器添加 fltk-config --ldflags
行即可避免链接器错误。请务必在该命令周围使用“`”符号,因为这是脚本并且应该执行它。
关于g++ - 将 FLTK 与 g++ 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47058727/