Page 1 of 1
Dependency problem building arm64+x86_64 for macOS
Posted: Mon Mar 11, 2024 8:43 pm
by jwwalker
I was trying to build universal (x86_64 + arm64) Ogre for macOS, but got a link error:
Code: Select all
Undefined symbols for architecture arm64:
"_png_do_expand_palette_rgb8_neon", referenced from:
_png_do_expand_palette in libFreeImage.a(pngrtran.o)
"_png_do_expand_palette_rgba8_neon", referenced from:
_png_do_expand_palette in libFreeImage.a(pngrtran.o)
"_png_riffle_palette_neon", referenced from:
_png_do_read_transformations in libFreeImage.a(pngrtran.o)
So I'm looking in the FreeImage part of the Ogre-Next-deps repo. I don't know much about CMake, but I'm suspicious of this section of the CMakeLists.txt file for FreeImage:
Code: Select all
if( CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" OR OGRE_BUILD_PLATFORM_APPLE_IOS )
set( FreeImage_SOURCES ${FreeImage_SOURCES}
Source/LibPNG/arm/arm_init.c
Source/LibPNG/arm/filter_neon_intrinsics.c
Source/LibPNG/arm/palette_neon_intrinsics.c
)
else()
set( FreeImage_SOURCES ${FreeImage_SOURCES}
Source/LibPNG/intel/filter_sse2_intrinsics.c
Source/LibPNG/intel/intel_init.c
)
endif()
To my untrained eye, it looks like that's going to use sources for Arm or for Intel, but not both, yet you'd need both to make a universal build. Is my analysis correct, and if so, what might a good fix be?
Re: Problem building arm64+x86_64 for macOS
Posted: Tue Mar 12, 2024 7:34 pm
by dark_sylinc
I suspect the arm64 build is sourcing the FreeImage library from the x86_64 build, somehow mixing ISAs.
Either that, or the CMAKE_SYSTEM_PROCESSOR checks never hit.
Try printf-debugging the CMake script by placing message( STATUS "Here" ).
I'm afraid I'm not very familiar with setting up Universal builds via CMake.
Re: Problem building arm64+x86_64 for macOS
Posted: Wed Mar 13, 2024 12:23 am
by jwwalker
I'm not sure what you mean by "the arm64 build". CMake should be creating a single Xcode project that builds both arm64 and x86_64. The top-level CMakeLists.txt file in Ogre-Next-Deps sets CMAKE_OSX_ARCHITECTURES by default to "$(ARCHS_STANDARD)", which will build both architectures. The CMAKE_SYSTEM_PROCESSOR test does get hit, but that's actually the problem: the architecture that's executing at the moment should not be the only architecture that gets built. In my case, I was building on an Intel-CPU machine, and as a result, FreeImage was built without all the sources needed for arm64. I think I'm beginning to understand this well enough to create a PR, if that would help.
Re: Problem building arm64+x86_64 for macOS
Posted: Thu Mar 14, 2024 4:20 pm
by dark_sylinc
Good Luck!
I can't help much, but I can tell you that when doing things like Universal building, these things are left to the generator (XCode in this case).
This means that certain variables stop working because they're evaluated by XCode and the script must be modified to account this. For example this happens with CMAKE_BUILD_TYPE (which can be Debug / Release / etc). It becomes blank for Visual Studio and XCode, because these IDEs can switch at runtime.
In the case of VS, one can use VS-specific language like $(ConfigurationName) e.g.
Code: Select all
link_directories( "${OGRE_BINARIES}/lib/$(ConfigurationName)" )
or sometimes CMake-specific options for specifying both Debug and Release:
Code: Select all
target_link_libraries( MyEXE debug MyLibrary_d )
target_link_libraries( MyEXE optimized MyLibrary )
Re: Problem building arm64+x86_64 for macOS
Posted: Thu Mar 14, 2024 5:33 pm
by jwwalker
I don't think comparing with VS helps much. In VS, at the top of the project window, a "solution platforms" menu can be used to choose Win32, x64, Arm64 etc., whereas in Xcode a single build operation often compiles for both arm64 and x86_64.
I've created a pull request.