FLTK - Mac iOS 图像未显示
Posted
技术标签:
【中文标题】FLTK - Mac iOS 图像未显示【英文标题】:FLTK - Mac iOS image not displayed 【发布时间】:2020-04-03 08:01:33 【问题描述】:我在 ios Mojave 10.14.6 上使用 FLTK 库(版本 1.3.5):我编写了这个简单的程序
#include <stdlib.h>
#include <FL/Fl.H>
#include <FL/platform.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Box.H>
int main(int argc, char **argv)
Fl_Window *G_win = 0;
G_win = new Fl_Window(650,650,"test");
Fl_Box* BG = new Fl_Box(0,0,650,650);
Fl_PNG_Image *bg = new Fl_PNG_Image("scheme.png");
BG->image(bg);
Fl_Box* text = new Fl_Box(250,20,150,20,"There should be an image down below. Is it so?");
G_win->end();
G_win->show(argc, argv);
return Fl::run();
我使用以下 Makefile 编译它(找到 here):
CC = $(shell fltk-config --cc)
CXX = $(shell fltk-config --cxx)
CFLAGS = $(shell fltk-config --cflags) -Wall -O3 -I/other/include/paths...
CXXFLAGS = $(shell fltk-config --cxxflags) -Wall -O3 -I/other/include/paths...
LINKFLTK = $(shell fltk-config --ldstaticflags)
LINKFLTK_GL = $(shell fltk-config --use-gl --ldstaticflags)
LINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags)
STRIP = strip
POSTBUILD = fltk-config --post # Required on OSX, does nothing on other platforms, so safe to call
all: myApp
main.o: main.cpp
$(CC) -c $< $(CCFLAGS)
myApp: main.o
$(CXX) -o $@ main.o $(LINKFLTK_IMG) $(LINKFLTK_GL)
$(STRIP) $@
$(POSTBUILD) $@ # only required on OSX, but call it anyway for portability
因此我得到二进制 myApp
和应用程序 myApp
:当我在 shell 中键入 ./myApp 时,一切工作正常(上图),而通过双击图标没有显示图像(下图)图片)。
我在编译过程中没有出错,也没有警告。 Makefile 有问题吗?是不是 Mac iOS 相关的?
【问题讨论】:
【参考方案1】:我猜这很简单,因为 FLTK 试图从 current 文件夹加载 PNG 文件。当您在 shell 中执行 ./myApp
时,它会在 PNG 文件所在的同一文件夹中运行。但是,当您双击时,您当前的路径就是谁知道在哪里。
最简单的“修复”是使用绝对路径(类似于“/home/youruser/work/myapp/scheme.png”),重新编译应用程序,然后运行它。 - 如果您提供了文件的完整路径,它应该可以工作。
【讨论】:
完美,你是对的,它就像一个魅力!我认为由于它们位于同一目录中,因此 .app 应该找到 png 文件。我想避免给出绝对路径,所以我会寻找一些方法来将图像包含在“.app bundle”中。我会尝试这里的建议:seriss.com/people/erco/fltk/#MacBundle 是的。这就是为什么我写它是“最简单”的修复。为示例或类似内容编写一个小型加载程序会更好。以上是关于FLTK - Mac iOS 图像未显示的主要内容,如果未能解决你的问题,请参考以下文章