Using external libraries with FLTK?

326 views
Skip to first unread message

Svets

unread,
Feb 29, 2016, 4:01:44 AM2/29/16
to fltk.general
I have built fltk on windows 7 64 bit and it built without error but I'm getting some issues when I set up lib and include files in my IDE (codeblocks) because I'm referencing both the internal libs included with fltk 1.3 like libpng and zlib and libjpeg and the external zlib, libjpeg, and libpng used for other libraries I'm using in my application.  I think the fact that I have two zlibs and two libpng's and two libjpeg's is the reason I'm getting errors.

What I want to do is to build fltk using the external zlib, libpng, and libjpeg but I'm having a little trouble getting them seen when I use the ./configure script.

I've tried using --prefix=C:/zlib but I can only put on there.
I've also tried using --includedir=C:/zlib but again I can only use one directory?

How to I divert the configure script to use these external libraries.  I can't tell if they are doing this or not as when I do try to divert them the output in my console says that 
zlib, libpng and libjpeg are BUILTIN?

Any clues as to how I would do this.

I also tried this.

./configure --includedir=C:/zlib  --includedir=C:/libpng --includedir=C:/libjpeg   .

of course only C:/libjpeg is the only directory seen and again I'm not even sure it was used.

Any clues?

Thanks

Albrecht Schlosser

unread,
Feb 29, 2016, 8:43:40 AM2/29/16
to fltkg...@googlegroups.com
On 29.02.2016 10:01 Svets wrote:
> I have built fltk on windows 7 64 bit and it built without error but I'm
> getting some issues when I set up lib and include files in my IDE
> (codeblocks) because I'm referencing both the internal libs included
> with fltk 1.3 like libpng and zlib and libjpeg and the external zlib,
> libjpeg, and libpng used for other libraries I'm using in my
> application. I think the fact that I have two zlibs and two libpng's
> and two libjpeg's is the reason I'm getting errors.

First important question: which compilers did you use to build FLTK? It
should be the same compiler you use in your IDE, otherwise the built
library might not be compatible with your IDE build.

> What I want to do is to build fltk using the external zlib, libpng, and
> libjpeg but I'm having a little trouble getting them seen when I use the
> ./configure script.

Okay, you build FLTK using configure. Again, which compiler and build
environment? MinGW?

> I've tried using --prefix=C:/zlib but I can only put on there.

--prefix is used for the target directory, i.e. where to install the
libs you build (FLTK).

> I've also tried using --includedir=C:/zlib but again I can only use one
> directory?

Hmm, no idea about this.

> How to I divert the configure script to use these external libraries. I
> can't tell if they are doing this or not as when I do try to divert them
> the output in my console says that
> zlib, libpng and libjpeg are BUILTIN?

If FLTK can't find the system libs, then it uses the "BUILTIN" libs,
i.e. the bundled libraries, for its own use. This can really be the
cause of trouble if you are using another version in your program.

> Any clues as to how I would do this.
>
> I also tried this.
>
> ./configure --includedir=C:/zlib --includedir=C:/libpng
> --includedir=C:/libjpeg .
>
> of course only C:/libjpeg is the only directory seen and again I'm not
> even sure it was used.
>
> Any clues?

You could try to build FLTK with CMake. In this case you can preset the
cache variables to use a particular zlib, png, and jpeg library:

$ cmake -LA | grep 'zlib\|png\|jpeg'

... shows ...

HAVE_LIBPNG_PNG_H:FILEPATH=/usr/include/libpng/png.h
HAVE_PNG_H:FILEPATH=/usr/include/png.h
JPEG_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libjpeg.so
LIB_jpeg:FILEPATH=/usr/lib/x86_64-linux-gnu/libjpeg.so
LIB_png:FILEPATH=/usr/lib/x86_64-linux-gnu/libpng.so
LIB_zlib:FILEPATH=/usr/lib/x86_64-linux-gnu/libz.so
PNG_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libpng.so

in my CMake build. You could try to preset these variables accordingly
(with cmake -D"...") or edit them manually with cmake-gui. You're
obviously using Windows, so cmake-gui might be the option to use. Just
install the Windows package from cmake.org, then execute cmake-gui.exe
from within your MinGW shell or whatever so cmake will find your
compilers. Select "Unix Makefiles" or "MSYS Makefiles" as the generator,
edit the variables shown above appropriately, and give this a try (click
configure + generate), then run make after leaving the gui. This may
work. Hopefully.

OTOH, if you want to use configure + make, you can try to edit
'makeinclude' after you run configure, or you can try to set CFLAGS,
CXXFLAGS, and LDFLAGS before you invoke configure, like this:

$ export CFLAGS="-I/path/to/zlib -I/path/to/libjpeg ..."
$ export CXXFLAGS="-I/path/to/zlib -I/path/to/libjpeg ..."
$ export LDFLAGS="-L/path/to/zlib -L/path/to/libjpeg ..."

./configure --disable-localzlib --disable-localpng --disable-localjpeg

make

Please let us know if you found a solution and how it worked. TIA.

MacArthur, Ian (Finmeccanica, UK)

unread,
Feb 29, 2016, 9:13:16 AM2/29/16
to fltkg...@googlegroups.com
> > getting some issues when I set up lib and include files in my IDE
> > (codeblocks) because I'm referencing both the internal libs included
> > with fltk 1.3 like libpng and zlib and libjpeg and the external zlib,
> > libjpeg, and libpng used for other libraries I'm using in my
> > application. I think the fact that I have two zlibs and two libpng's
> > and two libjpeg's is the reason I'm getting errors.


You don't want to use both the built-in and system libs, that will not go well.
As you have found...

> > What I want to do is to build fltk using the external zlib, libpng,
> and
> > libjpeg but I'm having a little trouble getting them seen when I use
> the
> > ./configure script.


> > I've also tried using --includedir=C:/zlib but again I can only use
> one
> > directory?
>
> Hmm, no idea about this.

Might respond to having the string enclosed, but I do not think so...

Could try:

./configure --includedir="C:/zlib c:/png etc."

but I think that will not work.



My preferred options, with Msys/mingw has usually been to either:-

- When I build my own PNG etc., I put the libs and headers into the appropriate places in the mingw hierarchy, so that mingw finds the headers and libs the same way as it does its own libs and files.

- or (if I build my own PNG with Msys) use Msys to "make install" the libs; that ensures the headers and lib files go to where the Msys "system" expects and again that usually Just Works.

- or, as Albrecht suggests, explicitly setting CFLAGS, CXXFLAGS and LDFLAGS to an initial state before passing them to configure. That approach is possibly the easiest, I guess, as that should work even if you are not using Msys later on (e.g. having built the fltk lib you want it to work with some other build environment!)




Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

Svets

unread,
Feb 29, 2016, 8:31:50 PM2/29/16
to fltk.general, Albrech...@online.de
I am using Mingw and the MSYS command line interface,  Forgot to mention that.  Will give this a try.

MacArthur, Ian (Finmeccanica, UK)

unread,
Mar 1, 2016, 5:03:03 AM3/1/16
to fltkg...@googlegroups.com
> I am using Mingw and the MSYS command line interface,
>  Forgot to mention that.  Will give this a try.

If you are building using mingw, from an Msys shell then it really should "Just Work" in that I have had success like this.

First, I configure/make zlib from source in the Msys shell, and "make install" it.

Then I configure/make libpng from its source - and it finds the Msys-installed zlib I just made.
And I "make install" libpng.

And so on...

Finally I configure fltk, and it finds the "installed" zlib, png, etc from above and things pretty much Just Work.

Is this not working for you on your setup? I think that it *ought* to at any rate!

Svets

unread,
Mar 1, 2016, 7:01:58 AM3/1/16
to fltk.general, ian.ma...@finmeccanica.com
It's that last part that doesnt' work for me.   When I'm building FLTK the libpng, zlib, and libjpeg aren't found. I've taken out the three directories for these libraries from the fltk directory so they don't get used.  They all build fine but I just can't connect them to FLTK. 

I'll try setting individual Environmental Variables for these three libraries.  

Cmake would probably work but i shouldn't need to use it.  I'd like to know how to configure this without cmak and by just using ./configure with some additions.

I'm not so sure how to use CXXFLAGS to connect them either. 

MacArthur, Ian (Finmeccanica, UK)

unread,
Mar 1, 2016, 8:08:46 AM3/1/16
to fltkg...@googlegroups.com
> It's that last part that doesnt' work for me. When I'm building FLTK
> the libpng, zlib, and libjpeg aren't found. I've taken out the three
> directories for these libraries from the fltk directory so they don't
> get used. They all build fine but I just can't connect them to FLTK.


OK, just to be clear here:

- You have built the "stock" versions of zlib, png, etc. in your Msys environment, from their respective tarballs, and that has worked OK?

- In doing this, libpng found the zlib you had already built/installed?

- And you have "installed" all of these into your Msys environment?

- If so, what paths are they installed at? What Msys path do they appear to be at? What "DOS" path are they actually at? I'm interested in where the respective header files end up, and where the lib files are put.


> I'll try setting individual Environmental Variables for these three
> libraries.

> Cmake would probably work but i shouldn't need to use it. I'd like to
> know how to configure this without cmak and by just using ./configure
> with some additions.

Yes, Cmake is good; Albrecht is a convert. But a lot of my kit just doesn't have Cmake (yet, anyway...!)

> I'm not so sure how to use CXXFLAGS to connect them either.


Well, it'd just be what Albrecht outlined before.
So assuming that Msys shows your png headers as being in "/usr/include/png" and the lib in "/usr/lib", and so on, then something like... (note these are the paths Msys sees, if you are building as Msys. You can *probably* use the full DOS path too, I expect, I have not tried!)

CXXFLAGS="-I/usr/include -I/usr/include/png -I/etc.."
export CXXFLAGS
CCFLAGS...etc
LDFLAGS="-L/usr/lib"
export LDFLAGS

./configure --disable-localpng -etc...

Then configure ought to be able to find these "system" libs as it runs and use them to build with. It should not matter if the built-in libs are also present.

Svets

unread,
Mar 2, 2016, 9:33:48 PM3/2/16
to fltk.general, ian.ma...@finmeccanica.com

Hi.. again.    

Sorry for the delay in replying.  I have been re-arranging my build environment so that everything is in simple directories such as c:/zlib etc.


- You have built the "stock" versions of zlib, png, etc. in your Msys environment, from their respective tarballs, and that has worked OK? 

Yes, all of these have been built and they built fine.  PNG found zlib without any trouble.


- In doing this, libpng found the zlib you had already built/installed? 
Yes.  


- And you have "installed" all of these into your Msys environment? 
I just spend some time rebuilding everything because I originally had all my dependencies in the C:/Dependencies/   directory but I ended up just placing all of them straight into the C:/ directory so all the libraries could be found.  Now, for example, zlib is at c:/zlib, libpng is at c:/libpng etc.    When I go to build fltk this is the command I'm using to configure my build.


./configure --disable-localzlib --disable-localpng --disable-localjpeg


- If so, what paths are they installed at? What Msys path do they appear to be at? What "DOS" path are they actually at? I'm interested in where the respective header files end up, and where the lib files are put. 
As above. So all in all here's my directory structure.

MSYS is at:
c:/msys/1.0

Mingw compiler is at: 
C:\mingw

zlib
c:\zlib

libpng
c:\libpng

libjpeg
c:\jpeg-6b

But still, when I configure this project the external libs as specified above cannot be seen.  Here's the relevant section of my configure process telling me this.
I have tried looking in the configure file to see what I can adjust to make the libraries visible but my knowledge of how these open source tool commands can be used in windows is limited.  I believe I can use --include-dir=  to indicate extra external libraries but I can only specify one external library such as c:/zlib

I often have this trouble when building open source libraries.  I think my directory structure is pretty sound now (it possibly wasn't before when I asked this question) but the problem still exists.  Maybe you can shed some light on this.

As for CMAKE, I have tried to create a makefile using CMAKE and I keep getting the below error message.  (See bottom of this post).  I'm still looking into why.  Ideally I would like to use MSYS to configure this so I would assume there must be a reason why I can't find my three system libraries zlib, png,jpeg.


checking for _FILE_OFFSET_BITS value needed for large files... 64
checking
for long long int... yes
checking
for library containing dlsym... no
checking dlfcn
.h usability... no
checking dlfcn
.h presence... no
checking
for dlfcn.h... no
checking
for jpeg_CreateCompress in -ljpeg... no
configure
: WARNING: Cannot find system jpeg lib or header: choosing the local lib mode.
checking
for gzgets in -lz... no
configure
: WARNING: Cannot find system z lib or header: choosing the local lib mode.
checking
for png_read_info in -lpng... no
configure
: WARNING: Cannot find system png lib or header: choosing the local lib mode.
checking GL
/gl.h usability... yes
checking GL
/gl.h presence... yes
checking
for GL/gl.h... yes
checking GL
/glu.h usability... yes
checking GL
/glu.h presence... yes
checking
for GL/glu.h... yes
checking
if GCC supports -fno-exceptions... yes
checking
if GCC supports -fno-strict-aliasing... yes
checking
if ld supports -Bsymbolic-functions... yes
checking
if toolchain supports sections... yes


Configuration Summary
-------------------------------------------------------------------------
   
Directories: prefix=/usr/local
                 bindir
=${exec_prefix}/bin
                 datadir
=${datarootdir}
                 datarootdir
=${prefix}/share
                 exec_prefix
=${prefix}
                 includedir
=${prefix}/include
                 libdir
=${exec_prefix}/lib
                 mandir
=${datarootdir}/man
                 
MSys docpath=C:/msys/1.0/local/share/doc/fltk
       
Graphics: GDI
Image Libraries: JPEG=Builtin
                 PNG
=Builtin
                 ZLIB
=Builtin
   
Large Files: YES
         
OpenGL: YES
       
Threads: YES
configure
: creating ./config.status
config
.status: creating makeinclude
config
.status: creating fltk.list
config
.status: creating fltk-config
config
.status: creating fltk.spec
config
.status: creating FL/Makefile
config
.status: creating config.h
config
.status: config.h is unchanged


user@USER
-PC /c/fltk
$

CMAKE Error Message
C:/fltk/FL/Fl_Widget.H:848:65: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   
void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);}
                                                                 
^
[ 44%] Building CXX object src/CMakeFiles/fltk_images.dir/Fl_JPEG_Image.cxx.obj
[ 44%] Building CXX object src/CMakeFiles/fltk_images.dir/Fl_PNG_Image.cxx.obj
In file included from C:\fltk\src\Fl_PNG_Image.cxx:40:0:
C
:/zlib/include/zlib.h:34:19: fatal error: zconf.h: No such file or directory
compilation terminated
.
src
\CMakeFiles\fltk_images.dir\build.make:212: recipe for target 'src/CMakeFiles/fltk_images.dir/Fl_PNG_Image.cxx.obj' failed
mingw32
-make[2]: *** [src/CMakeFiles/fltk_images.dir/Fl_PNG_Image.cxx.obj] Error 1
CMakeFiles\Makefile2:253: recipe for target 'src/CMakeFiles/fltk_images.dir/all' failed
mingw32
-make[1]: *** [src/CMakeFiles/fltk_images.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
mingw32
-make: *** [all] Error 2


C
:\fltk>

Svets

unread,
Mar 2, 2016, 10:58:45 PM3/2/16
to fltk.general, Albrech...@online.de
In reply to your suggestions Albrecht I have done the below.

These are the commands I used.. I'm using Mingw and MSYS.

export CFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
export CXXFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
export LDFLAGS="-LC:/zlib -LC:/libpng -LC:/jpeg-6b"

./configure --disable-localzlib --disable-localpng --disable-localjpeg

The above seems to have worked but libpng headers are still not seen.  The other external libraries (libjpeg and zlib) are seen.  It could be the version of my libpng that's the problem.  libpng version 1.6.21, January 15, 2016.

I'm going to try to put a lib and include directory in there to see if it makes any difference..

Your suggestions to export the CXXFLAGS etc worked perfectly.   I don't really understand what these are and how they work.  They will no doubt be useful in the future.  I don't suppose someone could explain exactly what they do as the explanations around the web are terrible.



On Tuesday, March 1, 2016 at 12:43:40 AM UTC+11, Albrecht Schlosser wrote:

Greg Ercolano

unread,
Mar 3, 2016, 12:14:52 AM3/3/16
to fltkg...@googlegroups.com
On 03/02/16 19:58, Svets wrote:
> export CFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
> export CXXFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
> export LDFLAGS="-LC:/zlib -LC:/libpng -LC:/jpeg-6b"
>
> ./configure --disable-localzlib --disable-localpng --disable-localjpeg
>
> The above seems to have worked but libpng headers are still not seen.


Hmm, I guess make sure that:

dir c:\libpng\png.h

..resolves. If it doesn't, check inside c:\libpng and see
if maybe the path is c:\libpng\libpng-1.6.21\png.h instead,
and if so, then use:

-IC:/libpng/libpng-1.6.21/

..instead. An easy problem to have.. not sure if that's it,
but it's all I can think of..

MacArthur, Ian (Finmeccanica, UK)

unread,
Mar 3, 2016, 5:38:33 AM3/3/16
to fltkg...@googlegroups.com
> Sorry for the delay in replying.

No worries.
Everybody is busy...

> I have been re-arranging my build
> environment so that everything is in simple directories such as c:/zlib
> etc.

OK. Um... I am not sure I would do that (actually, I'm sure I would not do that...)

I was under the impression that you were using Msys as your shell?

In that case, you should let Msys put all the things in the "right place" for you...

By that, I mean that Msys contrives to create a view of the filesystem that looks a lot like what a stock unix/posix filesystem would have.

The point being that then, when you build open-source code (much of which has a *nix ancestry) things just appear to be in the Right Place and it all just works.

So, the include files should *appear* to be in "/usr/include/*" the libs in "/usr/lib" etc.


So what I do, if I build libpng from source in an Msys shell, once it has built OK, I do a:

$ make install

in the Msys shell and that installs the headers and lib files in the "correct places" as viewed from within the Msys environment.

For example, this box (Win7 with Msys/mingw) shows this:


$ ls /usr/include
FlexLexer.h

$ ls /d/MinGW/msys/1.0/include/
FlexLexer.h

From this, we see that
(a) I don't have libpng on this box!
(b) Msys creates a "/usr/include" point in the filesystem
(c) that actually maps to "/d/MinGW/msys/1.0/include/" or (in DOS-speak) "D:\MinGW\msys\1.0\include"

But what matters here is that, when I run a configure script in an Msys shell, the first place it looks for headers is going to be in "/usr/include", and here it will find them.

Similarly for libs in "/usr/lib" of course.

And any external tools I happen to use, that still think in DOS-terms, they only need to be pointed to "D:\MinGW\msys\1.0\include" (or equivalent for your setup) and they also Just Work.

Svets

unread,
Mar 3, 2016, 6:40:14 AM3/3/16
to fltk.general, ian.ma...@finmeccanica.com
Thanks for explaining that.  My knowledge of these tools is scratchy at best. I didn't know any of this.
Either way, I will just have to make install a number of libraries.  

Albrecht Schlosser

unread,
Mar 3, 2016, 8:32:52 AM3/3/16
to fltkg...@googlegroups.com
On 03.03.2016 04:58 Svets wrote:
> In reply to your suggestions Albrecht I have done the below.
>
> These are the commands I used.. I'm using Mingw and MSYS.
>
> export CFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
> export CXXFLAGS="-IC:/zlib -IC:/libpng -IC:/jpeg-6b"
> export LDFLAGS="-LC:/zlib -LC:/libpng -LC:/jpeg-6b"
>
> ./configure --disable-localzlib --disable-localpng --disable-localjpeg
>
> The above seems to have worked but libpng headers are still not seen.
> The other external libraries (libjpeg and zlib) are seen. It could be
> the version of my libpng that's the problem. * libpng version 1.6.21,
> January 15, 2016.*

As Greg pointed out already, libpng installs itself (usually?) in an own
subdirectory, presumably because there are different versions (1.2.x,
1.5.x, 1.6.x) around.

I have under Linux for my self built libs:

drwxr-xr-x 2 root root 4096 Feb 12 15:39 /usr/local/xxx/include/libpng12
lrwxrwxrwx 1 root root 18 Feb 12 15:39
/usr/local/xxx/include/pngconf.h -> libpng12/pngconf.h
lrwxrwxrwx 1 root root 14 Feb 12 15:39 /usr/local/xxx/include/png.h ->
libpng12/png.h

As you can see there _is_ png.h, but it's a link to libpng12/png.h

In my MinGW environment I have instead:

drwxr-xr-x 2 ... 0 Oct 23 2014 /usr/local/xxx/include/libpng12
-rw-r--r-- 1 ... 162343 Oct 23 2014 /usr/local/xxx/include/png.h
-rw-r--r-- 1 ... 50346 Oct 23 2014 /usr/local/xxx/include/pngconf.h

Since MinGW can't create links it just duplicates the files, hence I
need only specify "-I/usr/local/xxx" to find all headers.

I used this (contrary to Ian's recommendation in my particular case)
because I need to install these particular libs in a _separate_ folder
than the default system libs. To do that I executed:

./configure --prefix=/usr/local/xxx ...

for all libs I built (default is either /usr or /usr/local, which should
do it as well, as Ian proposed).

Note: If you build zlib, libpng, and libjpeg with the same --prefix you
should be able to specify only this one library path for all libs you
built. And if you don't specify --prefix at all, you should not need to
specify one at all, as Ian suggested.

Note2: Don't try to copy the libs to their destination manually. You'd
better use configure --prefix=... if needed to build the libs, but be
also sure to use "make install" (again, as Ian recommends - I can only
agree).

> I'm going to try to put a lib and include directory in there to see if
> it makes any difference..

See above: use one --prefix=... to configure all the libs and use "make
install", then everything should be as you need it.

> Your suggestions to export the CXXFLAGS etc worked perfectly. I don't
> really understand what these are and how they work. They will no doubt
> be useful in the future. I don't suppose someone could explain exactly
> what they do as the explanations around the web are terrible.

It's not that difficult. CFLAGS is used to specify additional command
line flags for the C compiler (gcc), CXXFLAGS for the C++ compiler
(g++), resp.. LDFLAGS is used to specify flags for the linker. So you
can use CFLAGS and CXXFLAGS to specify the include directories and
LDFLAGS to specify the path(s) to the libs.

If you define (and export) these flags before you run configure then
they will be used to build the dependent library (let's say FLTK). Hence
the FLTK build will search for headers and libs in the specified paths.

FLTK will also save these flags in its fltk-config file, so you can run
these commands to see and use them later:

fltk-config --cflags
fltk-config --cxxflags
fltk-config --ldflags

and many more (use fltk-config --help to see more options).

Svets

unread,
Mar 6, 2016, 10:31:19 AM3/6/16
to fltk.general, Albrech...@online.de
I ended up using --prefix for all the depencencies and they were found just fine.  Thanks again for the explanations and help.  This has solved
allot of issues I've had in the past in this area.  
Reply all
Reply to author
Forward
0 new messages