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 "'Albrecht Schlosser' via fltk.general" 14:29 Mar 16  
 
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.

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.

I end up with:

[3/5] Linking CXX executable foo

ld: warning: ignoring duplicate libraries:
'fltk/install/lib/libfltk.a', 'fltk/install/lib/libfltk_jpeg.a',
'fltk/install/lib/libfltk_png.a', 'fltk/install/lib/libfltk_z.a'


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

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

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.

- 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.

- 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.

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.

--
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/cef9ea7b-006c-40a4-8aec-dfba9a626f0c%40aljus.de.
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'.