-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot build project with CMake (add_library cannot create ALIAS target "fltk" because target "fltk::fltk" is imported but not globally visible) #970
Comments
@sprkrd Thanks for the report, but I can't reproduce the error messages here. Please make sure that you have built and installed a fresh copy of FLTK and that the install directory is empty before you install FLTK. I tested to build your project directly from the FLTK build and from the installation folder. Both worked w/o issues. BTW (this may be helpful to avoid other issues): current docs (in
I strongly recommend to do this. One advantage is that you can inspect the cache variable with tools like Sidenote:
Although I can't reproduce this I remember that I had similar issues in the past but I couldn't find out yet what caused this. If you build from scratch and it doesn't work, then an easier workaround is to change only line 35 in
The generated aliases are only useful if you still use old FLTK target names like That said, I wonder what caused this error in your build. It would be very helpful if you could provide Could it be possible that CMake finds another (older) instance of FLTK on your system? |
@Albrecht-S Thank you for your rapid response! Actually, I have a strong preference against setting the I believe that the problem lies with CMake version. The version I use in this computer is 1.16, which should be fine according to README.CMake.txt. However, I've seen similar issues with alias exports with versions of CMake older than 1.23 in other unrelated libraries. Out of curiosity, what version of CMake are you using? Maybe the issue could just be solved by upgrading the CMake minimum requirement? I'll come back when I have a chance to try in a environment with a newer CMake. EDITED: Sorry! I mean't CMake 3.16, not 1.16. |
That's fine, as long as you set it as a cache variable on the commandline in the first CMake invocation. Our original recommendation to set it as a simple (non-cache) CMake variable is not recommended. If it's set as a cache variable you can inspect it after the build which is very helpful if there are any doubts (as in this case). Hint: If you don't need the system installation of FLTK I recommend to remove it just to be sure it doesn't affect the build. There are well-known issues when mixing header and binary files of self-built and system versions. However, that is only relevant later, at runtime.
[Typo 1.16 fixed in citation, must be 3.16] For my regular builds I'm using 3.25.1 (Debian Bookworm default), and that's what I used in my tests of your project. However, I have 6 older and newer versions present as well: from 3.15.0 (currently our minimum required version) up to 3.28.1 on my Debian system and even 3.29.2 on my Windows system where I have also several installed versions I can select. It is not impossible that a particular CMake version has a certain kind of bug that's fixed later. I know of some issues that have or have not been fixed in later versions. That said, I can test your project with CMake 3.15.0 and 3.18.0, the oldest versions I have presently available. Let's see if I can reproduce your issue, but I'd appreciate if you could test with other CMake versions as well. TIA.
I would like to stay conservative (i.e. keep 3.15) as long as possible (in FLTK 1.4.x). FLTK 1.5 will probably require a higher version. If I can reproduce the issue with one of my older versions there are chances I can work around the issue on the FLTK side. |
Oh, I wish I could do away with the old system FLTK installation, but unfortunately there are several packages that rely on it (ROS packages to be precise), and removing FLTK would wreak havoc on my system. No problem on my personal computers, where I can afford to install newer software. So, I've tested the newest version of CMake (v3.29) and it works without problem in all of my projects. Therefore, it'd seem there's some quirk in older versions of CMake involving aliases. |
OK, usually it shouldn't be necessary, it should work with two parallel versions, but we heard from users that mixed versions - with unexpected failures at runtime.
Thanks for testing and feedback. I've been busy with other FLTK stuff in the meantime, but with this information I'll definitely test your (and maybe other) project(s) with older CMake versions to see if I can confirm - and hopefully fix - this. I'll leave this issue open until I could test... |
Progress report:
I'll investigate this further and try to resolve the issue. At least we know now that
A very easy fix would be not to create the aliases if the CMake version is lower than 3.18.0, but I'll investigate further. It's good that I can reproduce the issue. |
... (add_library cannot create ALIAS target "fltk" because target "fltk::fltk" is imported but not globally visible) It turned out that this was due to a CMake feature that was changed in CMake 3.18. This commit makes imported FLTK targets globally visible for CMake versions less than 3.18.
Commit 6c06e95 fixes this issue by promoting all imported FLTK targets to global visibility for CMake versions less than 3.18. CMake 3.18 and later versions can create alias targets for imported targets with "local visibility" and don't need this extra step. FTR: I decided to keep the minimum CMake version at 3.15 and to fix this issue for versions < 3.18 only. This extra step will be removed when we require CMake 3.18 or higher in a later FLTK version. @sprkrd Please confirm if this fixes the issue for you and close this issue. Thanks. |
Describe the bug
When setting up a CMake project that uses FLTK, the following error messages pop up during the CMake configuration process:
I have to disable (comment out) lines 87 to 119 from the FLTKConfig.cmake file in order for CMake to succeed.
To Reproduce
I've followed the instructions from README.CMake.txt to build FLTK and set up the project. Here you'll find a FLTK project that used to work with the pre-release of FLTK v1.4 (like a year ago) and no longer works (unless I comment out lines 87 to 119 from FLTKConfig.cmake). I've adapted the project to the new changes described in README.CMake.txt (e.g. linking the executables to fltk::fltk-shared instead of fltk_SHARED).
Expected behavior
Successful configuration and compilation of the project.
Screenshots
N/A
FLTK Version
FLTK Configure / Build Options
Procedure for building:
The example project is built like so:
Operating System / Platform:
Please be as precise as possible, e.g. "Linux: Ubuntu 20.04"
Linux/Unix Runtime, if applicable:
N/A
Additional context
N/A
The text was updated successfully, but these errors were encountered: