On Windows, with MSVC as compiler, running on an MSYS64 shell, when
compiling dynamic DLLs (-DFLTK_BUILD_SHARED_LIBS=ON), there are a number
of issues:
On Wednesday, 4 October 2023 at 23:04:22 UTC+1 Gonzalo wrote:
On Windows, with MSVC as compiler, running on an MSYS64 shell, when
compiling dynamic DLLs (-DFLTK_BUILD_SHARED_LIBS=ON), there are a number
of issues:
I don't think I've ever tried that (using cl with cmake from an Msys shell.)
The problem is described on the CMakeLists.txt files and it has nothing to do with the compilation environment. It is an issue entirely with FLTK.
First, the issue is that FLTK's CMakeLists.txt files don't
properly support creating shared and static libs independently or
together. Currently, statict libs are always created, which, on
MSVC, also have a .lib extension.
On Windows, with the MSVC and DLL builds, only one DLL is created
that has all the libraries (fltk_gl, fltk, fltk_forms, etc) in
it. Why is that is not clearly explained as it is really easy to
have multiple DLLs. The main issue is the function
fl_add_library() in the functions.cmake.
-- Gonzalo Garramuño ggar...@gmail.com
On Wednesday, 4 October 2023 at 23:04:22 UTC+1 Gonzalo wrote:
On Windows, with MSVC as compiler, running on an MSYS64 shell, when
compiling dynamic DLLs (-DFLTK_BUILD_SHARED_LIBS=ON), there are a number
of issues:
I don't think I've ever tried that (using cl with cmake from an Msys shell.)
The problem is not the compile environment but an issue entirely
with FLTK's CMakeLists.txt files. It is, partially, explained
there in the comments.
FLTK does not allow turning off static lib compilation and always builds static one libraries. The problem with MSVC is that static libs and shared lib stubs both carry the .lib extension, which is confusing and since FLTK creates both, you'd get them overwritten.
To work around the issue, Albretch I think, when compiling with MSVC and shared builds, FLTK creates the static libs with a .lib extension, and only *ONE* DLL/.lib that has all the FLTK libs in it (fltk_gl, fltk, fltk_forms and fltk_images) with a "lib" *PREFIX*. It cannot get more confusing than that! Why not use a _SHARED or _DLL *SUFFIX* which would make it more clear, is beyond me.
IMHO, the fl_add_library() function defined in fl_add_library.cmake in the FLTK distribution is broken for MSVC. What's bad about compiling FLTK shared with MSVC is that there's no way to know the flags, compile switches or libraries from anywhere, as fltk-config just records the flags for the static libs and CMake's Config/Targets.cmake imports is built broken as you have only a single DLL, instead of several.
I did a dirty manual hack on my viewer to make it work, by
listing all the libs on Windows and had to pass the system DLLs
too and the -DFL_DLL flag. But I would like, with Albretch
permission, modify the FLTK CMake files to make them work properly
with CMake find_package() and multiple DLLs. If I can make it
work, I would submit a PR.
Gonzalo Garramuño ggar...@gmail.com
I took a closer look and I see the difficulty. The static libs are always created as the test, examples and more importantly fluid link to them. This is mainly a convenience to avoid users having DSO troubles with them.
However, it should still be possible to create a CMake Targets.cmake file for MSVC that links to the one and only DLL and has the compilation flags.
I made some progress in building only the shared libs (linking fluid and all test programs against the shared libs) but I postponed further work until the other libs stuff (see above) is done.
Albrecht Schlosser schrieb am Freitag, 6. Oktober 2023 um 11:23:56 UTC+2:
I made some progress in building only the shared libs (linking fluid and all test programs against the shared libs) but I postponed further work until the other libs stuff (see above) is done.
Thanks for all your work.
Two things: IMHO, if a user decides to only compile the shared libraries, I don't think that there is a need to build FLUID or any of the tests. Building "shared only" seems to me a decision to explicitly *not* build anything else.
If shared libs are requested, it is certainly useful to build one or two test apps that specifically link dynamically with multiple fltk DSO's, just to verify that the process is working.
With CMake developing very quickly and looking at our limited resources, would it make sense to try to get some external CMake expert involved, helping us to modernise our build setup? Maybe even if that person requires some reasonable pay.