1

I am using FLTK library (version 1.3.5) on iOS Mojave 10.14.6: I wrote this simple program

#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(); } 

and I compile it with the following Makefile (found 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 

I get hence the binary myApp and the application myApp: when I type ./myApp in the shell eveything works fine (top image), while by double-clicking on the icon there is no image displayed (bottom image).

Executing the binary double clicking on the app

I got no errors during compilation, nor warnings. Are there any problems with the Makefile? Is it Mac iOS related?

1 Answer 1

1

I guess it is so simply because FLTK is trying to load the PNG file from the current folder. When you execute ./myApp in the shell, it is running in the same folder where the PNG file is located. When you double-click however, your curent path is who-knows-where.

The simplest "fix" is to use an absolute path (something like "/home/youruser/work/myapp/scheme.png"), recompile the application, and run it. - It should work if you supplied the full path to the file.

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, you were right, it worked like a charm! I thought that since they are in the same directory the .app should have find the png file. I would like to avoid giving absolute paths, so I'll search some way to include the images in the ".app bundle". I will try what it is suggested here: seriss.com/people/erco/fltk/#MacBundle
Yep. That is why I wrote it was the "simplest" fix. Much better would be to write a tiny loader for an example, or similar.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.