crosscompiling to macos 10 linker issues

42 views
Skip to first unread message

Mo_Al_

unread,
May 1, 2024, 5:30:14 PMMay 1
to fltk.general
Hello

Currently FLTK uses UniformTypeIdentifiers on macos >= 11.
This is done using both CMake by checking the CMAKE_SYSTEM_VERSION >= 20 for the linking and  MAC_OS_X_VERSION_MAX_ALLOWED (in src/Fl_Native_File_Chooser_MAC.mm ) during the compilation.

According to the discussion here:
https://github.com/fltk-rs/fltk-rs/discussions/1541
this leads to issues when targeting macos 10 via cross-compilation.

The following Dockerfile would reproduce the issue. It uses a container which installs the osxcross toolchain:

FROM juanplopes/crossbuild

RUN git clone https://github.com/fltk/fltk --depth=1

ENV CROSS_TRIPLE=x86_64-apple-darwin

WORKDIR /workdir/fltk

ENV MACOSX_DEPLOYMENT_TARGET="10.9.0"

RUN crossbuild cmake -Bbin -DFLTK_BUILD_GL=OFF -DCMAKE_SYSTEM_NAME="Darwin" -DCMAKE_SYSTEM_VERSION="19.0.0"

RUN crossbuild cmake --build bin --parallel


removing the CMAKE_SYSTEM_VERSION breaks the build because CMake/setup.cmake relies on it being set. Using CMAKE_SYSTEM_VERSION 19 would cause a linker error. 
I haven't tried targeting macos 10 using an actual macos system, so I can't tell if this would also cause a build error there.

Thank you for your insights.

Manolo

unread,
May 2, 2024, 4:24:31 AMMay 2
to fltk.general
A first information:
I just tried here to build FLTK under macOS 10.9 and got no problem about missing symbol at link time.
In truth, there's an issue with the GL part I' going to fix but it has nothing to do with the problem at hand.

Manolo

unread,
May 2, 2024, 6:11:21 AMMay 2
to fltk.general
The fact there's a link error and not a compilation error suggests an incongruency between the macOS conditions used to compile (that is, the version of the SDK used) and the arguments of the link command used:
if symbol OBJC_CLASS$_UTType is needed at link time, it means the source has been compiled with an SDK version of macOS ≥ 11;
it means also that the link option "-framework UniformTypeIdentifiers" necessary to resolve this symbol is missing from the link command.

The adequate link option is defined by CMake by this if statement:
    if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 20.0.0)) # a.k.a. macOS version ≥ 11.0
Apparently, the cross build gives  ${CMAKE_SYSTEM_VERSION} a value < 20 so  "-framework UniformTypeIdentifiers" is omitted from the link command.
But this is not congruent with having used a version of the SDK ≥ 11.0 during the compilation step.
Caution: there are 2 distinct numbering systems here: that for macOS (we are now at macOS Sonoma14.x) used for SDKs
and that for Darwin used by CMAKE_SYSTEM_VERSION (macOS 14 corresponds to Darwin 23).

I believe the linux->macos cross-build operation with CMake should control these 2 CMake-defined variables
- CMAKE_OSX_SYSROOT  should specify the location or name of the macOS SDK used by the osxcross toolchain in use;
- CMAKE_OSX_DEPLOYMENT_TARGET should indicate the minimum version of a macOS system on which the executable will run (it must be equal or less than the version of the SDK given in CMAKE_OSX_SYSROOT).

See also the cmake doc for more details:

The source code of FLTK takes care of testing the macOS version of the running system and refrains from using symbols
belonging to macOS versions more recent than the running version. Thus, FLTK libraries can be built for recent macOS versions and run
on old macOS systems without problem provided the version given in CMAKE_OSX_DEPLOYMENT_TARGET is met.


Mohammed

unread,
May 2, 2024, 4:01:01 PMMay 2
to fltkg...@googlegroups.com
Thanks Manolo

This makes sense. I think it’s an osxcross issue more than anything. If the header is there and the compilation succeeds using it, then it makes sense to link UniformTypeIdentifiers. Otherwise an older sdk needs to be used. 

Sent from my iPhone

On 2 May 2024, at 13:11, Manolo <manol...@gmail.com> wrote:


--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/GwU31zGU9ao/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/b6284760-eb95-4d99-809a-17953abedfbfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages