You need to show us the configuration that you used to compile / link this code... Were you doing this inside of Xcode, or at the command line?
I'm inferring, from your wording, that you are in the Xcode IDE when this occurs?
> If I do not run the code inside the main function the program does not
> complain, so I assume it is finding the included libraries correctly.
I don't think so. It doesn't look to have resolved any of the fltk symbols at link time, so I’d infer that you have not linked your code against the fltk lib.
> I am not sure where that should happen
> exactly. Is that in Xcode?
If you are building this as an Xcode project, then the project settings (I don’t know which in Xcode 7...) would do this.
If you are compiling at the command line, then...
ld: library not found for -lfltk
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea what is this about and why? Is it the same issue you mention when you say:
It very much looks as if your code has (probably) compiled correctly, but during the linker phase you have not told the tools that they need to incorporate the fltk libs into the build.
Probably you need to add (at least) libfltk.a to the linker command line, possible others.
If you built the fltk libs with the configure script (it seems that you did) then a "fltk-config" script ought to have been generated as part of that process.
So, from a shell, in the fltk build dir, try:
fltk-config --ldstaticflags
And see what libraries it suggests you use.
/usr/local/lib/libfltk.a -lpthread -framework Cocoa
What should I do with these though? I am not sure what link against static FLTK library means. Either way I added the Cocoa framework in the meantime.
Also, note that if you are only building a single-file project, then at the command line all you need to do is:
fltk-config --compile my_file.cxx
And it will sort all that stuff out for you.
Macintosh:ch2_3 irvingangulo$ fltk-config --compile main.cpp
g++ -I/usr/local/include -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o 'main' 'main.cpp' /usr/local/lib/libfltk.a -lpthread -framework Cocoa
Creating 'main.app' bundle for desktop...
To work with FLTK and Xcode, it is possible to use the attached small Xcode project as follows :
.......
It is possible to replace main.cxx by another source file, and to add more files to build a bigger FLTK-based app
using FLTKproject.xcodeproj.
To work with FLTK and Xcode, it is possible to use the attached small Xcode project as follows :
1) put the compressed, attached file in the ....... fltk-1.3.3/ide/Xcode4 directory,
and decompress it (just double click will do it).
At this point FLTK.xcodeproj and FLTKproject.xcodeproj both sit in the same directory
2) build FLTK using Xcode: open FLTK.xcodeproj, select Fluid, the first of the long list
of targets of this project, and build.
3) open FLTKproject.xcodeproj and build and/or run.
The resulting FLTK application will be found in fltk-1.3.3/ide/Xcode4/build/Debug under the name FLTKapp
and is self-contained.
It is possible to replace main.cxx by another source file, and to add more files to build a bigger FLTK-based app
using FLTKproject.xcodeproj.
> I am trying to follow Stroustrup's PPP2. It is really the reason why I
> am trying to get FLTK. Other than that, FLTK library is completely alien
> to me, I will have to go on to see what Dr. S. comes up with.
OK - though I'd caution that Dr.S.'s use of fltk is somewhat, um, shall we say "idiosyncratic" in this book?
In particular, there are several things he does in his GUI wrapper framework that are rather contrary to what would be considered "normal" fltk usage.
It's been a while since I looked in detail, but if you are using the code samples from the website, you should probably be aware that the GUI framework has a "feature" (perhaps one might even say a bug) that makes it unreliable on a fast, multi-core OSX machine (pretty much any current OSX machine falls into that category!)
In his Simple_window::wait_for_button() method, where he wants to hold a window open (ignoring the window close button) then, instead of doing the "normal" fltk thing of catching and ignoring the window default callback (which is described in the fltk docs) instead he just spins in a loop calling redraw().
This may well have worked on older, slower, machines, but on modern machines it seems to be prone to some sort of deadlock.
It's a poor implementation choice, so do not be tempted to do the same in your own code, and if you get into difficulties running his examples, be aware that it might not be your fault!
Have fun, and I hope the learning experience goes well!
I'm on MacOS 10.11.6, and downloaded Xcode ?.? last week.
If I start Xcode and open .../fltk-1.3.3/ide/Xcode4/FLTK.xcodeproj
and follow the instructions in README.OSX.txt then Demo won't build.
In fl_line_style.cxx > [M] Fl_Graphics_Driver::line_style(...)
static enum CGLineCap Cap[4] =...
Elaborated type refers to a typedef
If instead I open the latest fltk-1.3.x from svn (11951?) I can get
Demo to build, but then Run Demo says:
My Macbook Pro cannot run Demo
My Macbook Pro runs MacOS 10.11.6 which is lower than Demo's
minimum deployment target. Change your project's minimum
deployment target or upgrade My Macbook Pro's version of MacOS.
When I downgrade the deployment target to 10.6 then Demo runs,
but each demo fails with a message similar to the following:
LSOpenURLsWithRole() failed with error -10825 for the file
/Users/duncan/Library/Developer/Xcode/DerivedData/.../Build/Products/Debug/cursor.app
As I was only curious about FLTK on Mac and using Xcode, I can't
be bothered to fight with the system to get it to work. And as
Xcode in its current configuration doesn't appear to offer class
navigation and refactoring support, then I might as well use vi
and make, which I know works.
I'm really surprised to have such a negative experience with Xcode.
Apple are famous for their user friendly and intuitive interfaces
and I'm really disappointed that Xcode doesn't fall in that category.
This is probably unfair, and it would probably make more sense if
I learned something about the MacOS ecosystem, but I'm not going
to spend any more time on Xcode.
D.