Dependency problem building arm64+x86_64 for macOS

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


jwwalker
Goblin
Posts: 267
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 19

Dependency problem building arm64+x86_64 for macOS

Post 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?

Last edited by jwwalker on Sat Mar 16, 2024 6:52 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: Problem building arm64+x86_64 for macOS

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

jwwalker
Goblin
Posts: 267
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 19

Re: Problem building arm64+x86_64 for macOS

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

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5476
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1358

Re: Problem building arm64+x86_64 for macOS

Post 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 )
jwwalker
Goblin
Posts: 267
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 19

Re: Problem building arm64+x86_64 for macOS

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