FLTK logo

Re: [fltk.general] Duplicated libraries

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Duplicated libraries Rob McDonald 15:43 Mar 16  
 
On Saturday, March 16, 2024 at 2:29:28 PM UTC-7 Albrecht-S wrote:
On 3/16/24 07:57 Rob McDonald wrote:
> I'm building with CMake, with FIND_PACKAGE(FLTK CONFIG REQUIRED).
>
> No matter whether I specify my libraries via:
>
> TARGET_LINK_LIBRARIES(foo
> ${FLTK_LIBRARIES}
> )

You should not do this since you want to take advantage of modern CMake.
FLTK_LIBRARIES contains *all* libraries generated by FLTK in our current
version of the config module.

The earlier/obsolete FindFLTK (1.1) module allowed to select which
libraries you need by setting some variables. In modern CMake you would
select "components" but this is not implemented in our FLTK build.

OK, in old (module based) FindFLTK.cmake, the above seemed to work.

Thanks much for the explanation -- it seems obvious (and I nearly went down that path).  I feel stupid for not knowing this.

> TARGET_LINK_LIBRARIES(foo
> fltk::z
> fltk::png
> fltk::jpeg
> fltk::fltk
> fltk::forms
> fltk::images
> fltk::gl
> )
>

You should not do this (in this form) as well. This would also (try to)
link all available FLTK libs. See below for suggestions.

> This seems harmless enough, ... Is anyone else seeing this sort of thing?

Do you see this on macOS, or on which OS?

I'm diagnosing this on MacOS, but it may happen on other platforms too.
 
I've never seen this on macOS but never on Linux, however only with
-lcairo and test/cairo_test.cxx where -lcairo was indeed linked twice. I
could change this by changing test/CMakeLists.txt so libcairo is not
added more than once.

What happens? Modern CMake adds linkage requirements to each library and
it should - IMHO - avoid duplicating libs. However, if you add libs more
than once, then I assume that CMake does it in the linker commandline as
well. That said,

- you should *never* add fltk::z, fltk::png, or fltk::jpeg explicitly
because they will be linked indirectly by fltk::images.

Where is this documented?  I had assumed that fltk::images contained some common image-related code and that the other three just contained format specific code.  I did not expect that the linker targets would be cumulative like this (to create the possibility of this mistake).

Also -- how can I be sure that it is safe to leave these out?  I probably can (I don't explicitly use any of the FLTK image code), but how can I be sure?  Is setting the operating system icon enough to require this?  Custom widget decorations?  I know I don't use FLTK to open and display images, but there might be some unintended use.

 
- if you need one or more of fltk::forms, fltk::images, or fltk::gl then
add them to your target_link_libraries() but not fltk::fltk because it
will be included implicitly. Using all three of these libs should be
harmless.

Again, where is this documented?  Is fltk::forms only needed for old  Forms compatibility?

OK, I've gone searching more and have found this stuff documented in section 3.1 of README.CMake.txt

It is super interesting that fltk::forms, fltk::images, and fltk::gl will all implicitly add fltk::fltk -- such that adding all three is harmless and adding any of them makes fltk::fltk unnecessary.  However, there are the other prohibitions against multiple adds...

From reading all this, I think I should be able to get away with just 

fltk::gl

And nothing else...


- if you don't use one of the libs above, add *only* fltk::fltk to
target_link_libraries().

The most likely set of libs you will need to use is (I'm guessing)
fltk::images + fltk::gl (if you use OpenGL) but very likely not fltk::forms.

This *should* avoid multiply linking libs and the warning message should
- hopefully - disappear. If this is not the case, then it's either a bug
in FLTK's CMake files or in CMake itself and I would like to see more
details.

BTW, the 'old' FindFLTL.cmake Module approach would implicitly 'Find(OpenGL)' (unless it was explicitly skipped) and would add the resulting OpenGL libraries to the FLTK libraries.

This does not appear to be what fltk::gl does at all -- which is fine, but I guess this is just another implied difference between the old and Modern way.
 
You can find out more if you look at the linker command by doing
something like this to avoid too much noise:

1. build/link your app normally
2. delete the executable
3. link your app again in verbose mode, e.g. `cmake --build . --verbose`

The 3rd command should show you only the linker commandline. There are
several other ways to make the build "verbose", e.g. `ninja -v` if you
build with ninja, or `make VERBOSE=1 <target>` if you're using make.

However this might or might not give you a clue *why* a particular lib
is linked more than once.

This is generally how I have been diagnosing this sort of thing already.  However, this does not tell me that fltk::images includes all of fltk::jpeg and fltk::png  -- and other implied rules like that.

Thanks for the help,

Rob


 

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/432d975d-6c2e-4db7-af63-8041962e5dd7n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.